Permalink
Browse files

fix issue #354 Template undefined references

  • Loading branch information...
1 parent e2086fd commit 00110751fff0132bf3dd98f0f397098d6797b69c @ibuclaw ibuclaw committed Jul 1, 2012
Showing with 34 additions and 31 deletions.
  1. +12 −0 gcc/d/ChangeLog
  2. +5 −11 gcc/d/d-decls.cc
  3. +4 −8 gcc/d/d-glue.cc
  4. +11 −8 gcc/d/d-objfile.cc
  5. +0 −2 gcc/d/symbol.cc
  6. +2 −2 gcc/d/symbol.h
View
@@ -1,5 +1,17 @@
2012-07-01 Iain Buclaw <ibuclaw@ubuntu.com>
+ * symbol.h(deferredNestedFuncs): Renamed from otherNestedFuncs, use as
+ value type rather than pointer.
+ (thunks): Use as value type rather than pointer.
+ * d-decls.cc(FuncDeclaration::toSymbol): Remove check for
+ deferredNestedFuncs being NULL.
+ (FuncDeclaration::toThunkSymbol): Remove check for thunks being NULL.
+ * d-glue.cc(DelegateExp::toElem): Remove check for deferredNestedFuncs
+ being NULL.
+ (FuncDeclaration::toObjFile): Likewise.
+ * d-objfile.cc(ObjectFile::shouldEmit): Add nested functions to
+ deferredNestedFuncs of their parent function incase parent is actually
+ emitted later in during compilation.
* d-builtins2.cc(d_gcc_type_align): Explicit alignment of variables
takes precedence over default alignment.
* d-gcc-includes.h: Re-order list of includes.
View
@@ -531,12 +531,9 @@ FuncDeclaration::toSymbol ()
if (is_template_member && outer_func)
{
Symbol * outer_sym = outer_func->toSymbol ();
+
if (outer_sym->outputStage != Finished)
- {
- if (! outer_sym->otherNestedFuncs)
- outer_sym->otherNestedFuncs = new FuncDeclarations;
- outer_sym->otherNestedFuncs->push (this);
- }
+ outer_sym->deferredNestedFuncs.push (this);
}
// Save context and set decl_function_context for cgraph.
@@ -640,14 +637,11 @@ FuncDeclaration::toThunkSymbol (int offset)
/* If the thunk is to be static (that is, it is being emitted in this
module, there can only be one FUNCTION_DECL for it. Thus, there
is a list of all thunks for a given function. */
- if (! csym->thunks)
- csym->thunks = new Thunks;
- Thunks & thunks = * csym->thunks;
bool found = false;
- for (size_t i = 0; i < thunks.dim; i++)
+ for (size_t i = 0; i < csym->thunks.dim; i++)
{
- thunk = thunks[i];
+ thunk = csym->thunks[i];
if (thunk->offset == offset)
{
found = true;
@@ -659,7 +653,7 @@ FuncDeclaration::toThunkSymbol (int offset)
{
thunk = new Thunk;
thunk->offset = offset;
- thunks.push (thunk);
+ csym->thunks.push (thunk);
}
if (! thunk->symbol)
View
@@ -1860,9 +1860,7 @@ DelegateExp::toElem (IRState* irs)
if (owner->isTemplateInstance () || owner == irs->mod)
{
Symbol * s = irs->func->toSymbol ();
- if (!s->otherNestedFuncs)
- s->otherNestedFuncs = new FuncDeclarations;
- s->otherNestedFuncs->push (func);
+ s->deferredNestedFuncs.push (func);
}
}
@@ -3099,12 +3097,10 @@ FuncDeclaration::toObjFile (int /*multiobj*/)
fbody->toIR (irs);
- if (this_sym->otherNestedFuncs)
+ // Process all deferred nested functions.
+ for (size_t i = 0; i < this_sym->deferredNestedFuncs.dim; ++i)
{
- for (size_t i = 0; i < this_sym->otherNestedFuncs->dim; ++i)
- {
- (this_sym->otherNestedFuncs->tdata()[i])->toObjFile (false);
- }
+ (this_sym->deferredNestedFuncs[i])->toObjFile (false);
}
if (v_argptr)
View
@@ -438,21 +438,24 @@ ObjectFile::shouldEmit (Declaration * d_sym)
return false;
}
- // Don't emit nested functions whose parent isn't being emitted.
- fd = fd->toParent2()->isFuncDeclaration ();
- if (fd && fd->toSymbol()->outputStage == NotStarted)
- return false;
+ // Defer emitting nested functions whose parent isn't started yet.
+ // If the parent never gets emitted, then neither will fd.
+ FuncDeclaration * outerfd = fd->toParent2()->isFuncDeclaration ();
+ if (outerfd && outerfd->toSymbol()->outputStage == NotStarted)
+ {
+ outerfd->toSymbol()->deferredNestedFuncs.push (fd);
+ return false;
+ }
}
- Symbol * s = d_sym->toSymbol ();
- gcc_assert (s);
-
- return shouldEmit (s);
+ return shouldEmit (d_sym->toSymbol ());
}
bool
ObjectFile::shouldEmit (Symbol * sym)
{
+ gcc_assert (sym);
+
// If have already started emitting, continue doing so.
if (sym->outputStage)
return true;
View
@@ -33,8 +33,6 @@ Symbol::Symbol ()
ScontextDecl = 0;
SframeField = 0;
- thunks = NULL;
- otherNestedFuncs = NULL;
outputStage = NotStarted;
frameInfo = NULL;
}
View
@@ -97,8 +97,8 @@ struct Symbol : Object
tree SframeField; // FIELD_DECL in frame struct that this variable is allocated in
// For FuncDeclarations:
- Thunks * thunks;
- FuncDeclarations * otherNestedFuncs;
+ Thunks thunks;
+ FuncDeclarations deferredNestedFuncs;
OutputStage outputStage;
FuncFrameInfo *frameInfo;
};

0 comments on commit 0011075

Please sign in to comment.