DeclUnloader: remove StaticVarCollector
StaticVarCollector recursively visited descendants of a `FunctionDecl` node to collect static local variables. However, these always appear in the enclosing DeclContext.
This commit is contained in:
parent
a292a61b28
commit
33a63913b3
@ -327,24 +327,6 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef llvm::SmallVector<VarDecl*, 2> Vars;
|
|
||||||
class StaticVarCollector : public RecursiveASTVisitor<StaticVarCollector> {
|
|
||||||
Vars& m_V;
|
|
||||||
|
|
||||||
public:
|
|
||||||
StaticVarCollector(FunctionDecl* FD, Vars& V) : m_V(V) {
|
|
||||||
TraverseStmt(FD->getBody());
|
|
||||||
}
|
|
||||||
bool VisitDeclStmt(DeclStmt* DS) {
|
|
||||||
for (DeclStmt::decl_iterator I = DS->decl_begin(), E = DS->decl_end();
|
|
||||||
I != E; ++I)
|
|
||||||
if (VarDecl* VD = dyn_cast<VarDecl>(*I))
|
|
||||||
if (VD->isStaticLocal())
|
|
||||||
m_V.push_back(VD);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Template instantiation of templated function first creates a canonical
|
// Template instantiation of templated function first creates a canonical
|
||||||
// declaration and after the actual template specialization. For example:
|
// declaration and after the actual template specialization. For example:
|
||||||
// template<typename T> T TemplatedF(T t);
|
// template<typename T> T TemplatedF(T t);
|
||||||
@ -677,15 +659,18 @@ namespace cling {
|
|||||||
// which we will remove soon. (Eg. mangleDeclName iterates the redecls)
|
// which we will remove soon. (Eg. mangleDeclName iterates the redecls)
|
||||||
GlobalDecl GD(FD);
|
GlobalDecl GD(FD);
|
||||||
MaybeRemoveDeclFromModule(GD);
|
MaybeRemoveDeclFromModule(GD);
|
||||||
|
|
||||||
// Handle static locals. void func() { static int var; } is represented in
|
// Handle static locals. void func() { static int var; } is represented in
|
||||||
// the llvm::Module is a global named @func.var
|
// the llvm::Module is a global named @func.var
|
||||||
Vars V;
|
for (auto D : FunctionDecl::castToDeclContext(FD)->noload_decls()) {
|
||||||
StaticVarCollector c(FD, V);
|
if (auto VD = dyn_cast<VarDecl>(D))
|
||||||
for (Vars::iterator I = V.begin(), E = V.end(); I != E; ++I) {
|
if (VD->isStaticLocal()) {
|
||||||
GlobalDecl GD(*I);
|
GlobalDecl GD(VD);
|
||||||
MaybeRemoveDeclFromModule(GD);
|
MaybeRemoveDeclFromModule(GD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// VisitRedeclarable() will mess around with this!
|
// VisitRedeclarable() will mess around with this!
|
||||||
bool wasCanonical = FD->isCanonicalDecl();
|
bool wasCanonical = FD->isCanonicalDecl();
|
||||||
// FunctionDecl : DeclaratiorDecl, DeclContext, Redeclarable
|
// FunctionDecl : DeclaratiorDecl, DeclContext, Redeclarable
|
||||||
|
Loading…
Reference in New Issue
Block a user