aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2019-03-20 23:52:48 +0000
committerIain Buclaw <ibuclaw@gcc.gnu.org>2019-03-20 23:52:48 +0000
commit9dddefefdf407376ed3a0bba09a14f65b194898d (patch)
tree1c5d4ec04a8021ff8e31befda84fa58201e0fb9b /gcc/d
parent5d2df818b7752021425581455aca08f3fd0902b7 (diff)
downloadgcc-9dddefefdf407376ed3a0bba09a14f65b194898d.zip
gcc-9dddefefdf407376ed3a0bba09a14f65b194898d.tar.gz
gcc-9dddefefdf407376ed3a0bba09a14f65b194898d.tar.bz2
d: Fix ICE force_type_die, at dwarf2out.c using nested types
In functions whose return type is instantiated from a nested template, make sure that all members of the instance are emitted before finishing the outer function, otherwise they will be removed during the prune_unused_types pass. gcc/d/ChangeLog: 2019-03-21 Iain Buclaw <ibuclaw@gdcproject.org> PR d/89017 * d-codegen.cc (d_decl_context): Skip over template instances when finding the context. * decl.cc (DeclVisitor::visit(TemplateDeclaration)): New override. (build_type_decl): Include parameters in name of template types. gcc/testsuite/ChangeLog: 2019-03-21 Iain Buclaw <ibuclaw@gdcproject.org> PR d/89017 * gdc.dg/pr89017.d: New test. From-SVN: r269828
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/ChangeLog8
-rw-r--r--gcc/d/d-codegen.cc7
-rw-r--r--gcc/d/decl.cc41
3 files changed, 49 insertions, 7 deletions
diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog
index 8e45c7f..39df9b8 100644
--- a/gcc/d/ChangeLog
+++ b/gcc/d/ChangeLog
@@ -1,3 +1,11 @@
+2019-03-21 Iain Buclaw <ibuclaw@gdcproject.org>
+
+ PR d/89017
+ * d-codegen.cc (d_decl_context): Skip over template instances when
+ finding the context.
+ * decl.cc (DeclVisitor::visit(TemplateDeclaration)): New override.
+ (build_type_decl): Include parameters in name of template types.
+
2019-03-13 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/88957
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index e8233b4..2692910 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -67,7 +67,7 @@ d_decl_context (Dsymbol *dsym)
Dsymbol *parent = dsym;
Declaration *decl = dsym->isDeclaration ();
- while ((parent = parent->toParent ()))
+ while ((parent = parent->toParent2 ()))
{
/* We've reached the top-level module namespace.
Set DECL_CONTEXT as the NAMESPACE_DECL of the enclosing module,
@@ -101,11 +101,6 @@ d_decl_context (Dsymbol *dsym)
return context;
}
-
- /* Instantiated types are given the context of their template. */
- TemplateInstance *ti = parent->isTemplateInstance ();
- if (ti != NULL && decl == NULL)
- parent = ti->tempdecl;
}
return NULL_TREE;
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 7edfe52..fffed97 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -255,6 +255,40 @@ public:
}
}
+ /* Templates are D's approach to generic programming. They have no members
+ that can be emitted, however if the template is nested and used as a
+ voldemort type, then it's members must be compiled before the parent
+ function finishes. */
+
+ void visit (TemplateDeclaration *d)
+ {
+ /* Type cannot be directly named outside of the scope it's declared in, so
+ the only way it can be escaped is if the function has auto return. */
+ FuncDeclaration *fd = d_function_chain ? d_function_chain->function : NULL;
+
+ if (!fd || !fd->isAuto ())
+ return;
+
+ /* Check if the function returns an instantiated type that may contain
+ nested members. Only applies to classes or structs. */
+ Type *tb = fd->type->nextOf ()->baseElemOf ();
+
+ while (tb->ty == Tarray || tb->ty == Tpointer)
+ tb = tb->nextOf ()->baseElemOf ();
+
+ TemplateInstance *ti = NULL;
+
+ if (tb->ty == Tstruct)
+ ti = ((TypeStruct *) tb)->sym->isInstantiated ();
+ else if (tb->ty == Tclass)
+ ti = ((TypeClass *) tb)->sym->isInstantiated ();
+
+ /* Return type is instantiated from this template declaration, walk over
+ all members of the instance. */
+ if (ti && ti->tempdecl == d)
+ ti->accept (this);
+ }
+
/* Walk over all members in the instantiated template. */
void visit (TemplateInstance *d)
@@ -2228,8 +2262,13 @@ build_type_decl (tree type, Dsymbol *dsym)
gcc_assert (!POINTER_TYPE_P (type));
+ /* If a templated type, use the template instance name, as that includes all
+ template parameters. */
+ const char *name = dsym->parent->isTemplateInstance ()
+ ? ((TemplateInstance *) dsym->parent)->toChars () : dsym->ident->toChars ();
+
tree decl = build_decl (make_location_t (dsym->loc), TYPE_DECL,
- get_identifier (dsym->ident->toChars ()), type);
+ get_identifier (name), type);
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (mangle_decl (dsym)));
TREE_PUBLIC (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;