Skip to content

Commit

Permalink
Fixed getParentFunc(..., true) as used for nested context creation.
Browse files Browse the repository at this point in the history
It seems like the original code contained two issues: First,
the stopOnStatic branch checked the passed symbol over and
over again instead of the current parent. Second, aggregate
declarations are not Declarations, they are ScopeDsymbols.

GitHub: Fixes ldc-developers#696.
  • Loading branch information
dnadlinger committed Oct 10, 2014
1 parent 21d0ff4 commit f6ecdec
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,19 +1902,32 @@ llvm::GlobalVariable* getOrCreateGlobal(Loc& loc, llvm::Module& module,
#endif
}

FuncDeclaration* getParentFunc(Dsymbol* sym, bool stopOnStatic) {
FuncDeclaration* getParentFunc(Dsymbol* sym, bool stopOnStatic)
{
if (!sym)
return NULL;

Dsymbol* parent = sym->parent;
assert(parent);
while (parent && !parent->isFuncDeclaration()) {
if (stopOnStatic) {
Declaration* decl = sym->isDeclaration();
if (decl && decl->isStatic())
return NULL;

while (parent && !parent->isFuncDeclaration())
{
if (stopOnStatic)
{
// Fun fact: AggregateDeclarations are not Declarations.
if (FuncDeclaration* decl = parent->isFuncDeclaration())
{
if (decl->isStatic())
return NULL;
}
else if (AggregateDeclaration* decl = parent->isAggregateDeclaration())
{
if (!decl->isNested())
return NULL;
}
}
parent = parent->parent;
}

return (parent ? parent->isFuncDeclaration() : NULL);
return parent ? parent->isFuncDeclaration() : NULL;
}

0 comments on commit f6ecdec

Please sign in to comment.