Skip to content

Commit

Permalink
fix Issue 7595 - Data being overwritten.
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Mar 5, 2012
1 parent 3a523fd commit d531901
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ struct FuncDeclaration : Declaration
VarDeclarations closureVars; // local variables in this function
// which are referenced by nested
// functions
FuncDeclarations deferred; // toObjFile() these functions after this one

unsigned flags;
#define FUNCFLAGpurityInprocess 1 // working on determining purity
Expand Down
2 changes: 2 additions & 0 deletions src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3428,7 +3428,9 @@ elem *DelegateExp::toElem(IRState *irs)
//printf("DelegateExp::toElem() '%s'\n", toChars());

if (func->semanticRun == PASSsemantic3done)
{
irs->deferToObj->push(func);
}

sfunc = func->toSymbol();
if (func->isNested())
Expand Down
24 changes: 23 additions & 1 deletion src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,32 @@ void FuncDeclaration::toObjFile(int multiobj)

for (size_t i = 0; i < irs.deferToObj->dim; i++)
{
Dsymbol *s = irs.deferToObj->tdata()[i];
Dsymbol *s = (*irs.deferToObj)[i];

FuncDeclaration *fd = s->isFuncDeclaration();
if (fd)
{ FuncDeclaration *fdp = fd->toParent2()->isFuncDeclaration();
if (fdp && fdp->semanticRun < PASSobj)
{ /* Bugzilla 7595
* FuncDeclaration::buildClosure() relies on nested functions
* being toObjFile'd after the outer function. Otherwise, the
* v->offset's for the closure variables are wrong.
* So, defer fd until after fdp is done.
*/
fdp->deferred.push(fd);
continue;
}
}

s->toObjFile(0);
}

for (size_t i = 0; i < deferred.dim; i++)
{
FuncDeclaration *fd = deferred[i];
fd->toObjFile(0);
}

#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
// A hack to get a pointer to this function put in the .dtors segment
if (ident && memcmp(ident->toChars(), "_STD", 4) == 0)
Expand Down

0 comments on commit d531901

Please sign in to comment.