aboutsummaryrefslogtreecommitdiff
path: root/gcc/d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-09-12 16:26:58 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2020-09-12 21:34:38 +0200
commite4011c13c1f8d51f00af61bcb8189bcbe45823b7 (patch)
tree613e7276d4ebf04ef64d1546cff0fdded9d58bd1 /gcc/d
parent49482217e0ade3fe92ea050c01f5f7a6ddc31e95 (diff)
downloadgcc-e4011c13c1f8d51f00af61bcb8189bcbe45823b7.zip
gcc-e4011c13c1f8d51f00af61bcb8189bcbe45823b7.tar.gz
gcc-e4011c13c1f8d51f00af61bcb8189bcbe45823b7.tar.bz2
d: Build TYPE_DECLs for non-numeric enum types.
This is done so that the DWARF pass will emit a DW_TAG_typedef where the member type of an enum can't be represented in an ENUMERAL_TYPE. gcc/d/ChangeLog: * d-builtins.cc (d_build_d_type_nodes): Call build_ctype() on all basic front-end types. * decl.cc (DeclVisitor::visit (EnumDeclaration *)): Always add decl to current binding level. (build_type_decl): Build TYPE_DECL as a typedef if not for an enum or record type. * types.cc (TypeVisitor::visit (TypeEnum *)): Set underlying type for ENUMERAL_TYPEs. Build TYPE_DECL for non-numeric enums.
Diffstat (limited to 'gcc/d')
-rw-r--r--gcc/d/d-builtins.cc8
-rw-r--r--gcc/d/decl.cc22
-rw-r--r--gcc/d/types.cc5
3 files changed, 24 insertions, 11 deletions
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index e3d7adc..72e2d3a 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -848,6 +848,14 @@ d_build_d_type_nodes (void)
ireal_type_node = build_distinct_type_copy (long_double_type_node);
TYPE_IMAGINARY_FLOAT (ireal_type_node) = 1;
+ /* Calling build_ctype() links the front-end Type to the GCC node,
+ and sets the TYPE_NAME to the D language type. */
+ for (unsigned ty = 0; ty < TMAX; ty++)
+ {
+ if (Type::basic[ty] != NULL)
+ build_ctype (Type::basic[ty]);
+ }
+
/* Used for ModuleInfo, ClassInfo, and Interface decls. */
unknown_type_node = make_node (RECORD_TYPE);
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc
index 59844bc..161a85a 100644
--- a/gcc/d/decl.cc
+++ b/gcc/d/decl.cc
@@ -618,13 +618,13 @@ public:
d_linkonce_linkage (d->sinit);
d_finish_decl (d->sinit);
-
- /* Add this decl to the current binding level. */
- tree ctype = build_ctype (d->type);
- if (TREE_CODE (ctype) == ENUMERAL_TYPE && TYPE_NAME (ctype))
- d_pushdecl (TYPE_NAME (ctype));
}
+ /* Add this decl to the current binding level. */
+ tree ctype = build_ctype (d->type);
+ if (TYPE_NAME (ctype))
+ d_pushdecl (TYPE_NAME (ctype));
+
d->semanticRun = PASSobj;
}
@@ -2270,8 +2270,6 @@ build_type_decl (tree type, Dsymbol *dsym)
if (TYPE_STUB_DECL (type))
return;
- 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 ()
@@ -2281,7 +2279,6 @@ build_type_decl (tree type, Dsymbol *dsym)
get_identifier (name), type);
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (d_mangle_decl (dsym)));
TREE_PUBLIC (decl) = 1;
- DECL_ARTIFICIAL (decl) = 1;
DECL_CONTEXT (decl) = d_decl_context (dsym);
TYPE_CONTEXT (type) = DECL_CONTEXT (decl);
@@ -2290,9 +2287,14 @@ build_type_decl (tree type, Dsymbol *dsym)
/* Not sure if there is a need for separate TYPE_DECLs in
TYPE_NAME and TYPE_STUB_DECL. */
if (TREE_CODE (type) == ENUMERAL_TYPE || RECORD_OR_UNION_TYPE_P (type))
- TYPE_STUB_DECL (type) = decl;
+ {
+ DECL_ARTIFICIAL (decl) = 1;
+ TYPE_STUB_DECL (type) = decl;
+ }
+ else if (type != TYPE_MAIN_VARIANT (type))
+ DECL_ORIGINAL_TYPE (decl) = TYPE_MAIN_VARIANT (type);
- rest_of_decl_compilation (decl, SCOPE_FILE_SCOPE_P (decl), 0);
+ rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
}
/* Create a declaration for field NAME of a given TYPE, setting the flags
diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index 994d0b9..6df1e78 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -859,14 +859,17 @@ public:
For these, we simplify this a little by using the base type directly
instead of building an ENUMERAL_TYPE. */
t->ctype = build_variant_type_copy (basetype);
+ build_type_decl (t->ctype, t->sym);
}
else
{
t->ctype = make_node (ENUMERAL_TYPE);
- ENUM_IS_SCOPED (t->ctype) = 1;
TYPE_LANG_SPECIFIC (t->ctype) = build_lang_type (t);
d_keep (t->ctype);
+ ENUM_IS_SCOPED (t->ctype) = 1;
+ TREE_TYPE (t->ctype) = basetype;
+
if (flag_short_enums)
TYPE_PACKED (t->ctype) = 1;