]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix internal compiler error: in d_init_builtins, at d/d-builtins.cc:1121
authoribuclaw <ibuclaw@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 07:53:05 +0000 (07:53 +0000)
committeribuclaw <ibuclaw@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 07:53:05 +0000 (07:53 +0000)
gcc/d/ChangeLog:

PR d/90444
* d-builtins.cc (build_frontend_type): Build anonymous RECORD_TYPE
nodes as well, push all fields to the struct members.
(d_build_builtins_module): Push anonymous va_list structs to the
builtins module, naming them __builtin_va_list.
(d_init_builtins): Use sorry instead of gcc_unreachable if va_list did
not succeed in being represented as a D type.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274765 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/d/ChangeLog
gcc/d/d-builtins.cc

index a4db1facbf844b6a2aad5d67659b391bd852d1f1..00845df4de177d42184b81362559cc7c958c9f8a 100644 (file)
@@ -1,3 +1,13 @@
+2019-08-20  Iain Buclaw  <ibuclaw@gdcproject.org>
+
+       PR d/90444
+       * d-builtins.cc (build_frontend_type): Build anonymous RECORD_TYPE
+       nodes as well, push all fields to the struct members.
+       (d_build_builtins_module): Push anonymous va_list structs to the
+       builtins module, naming them __builtin_va_list.
+       (d_init_builtins): Use sorry instead of gcc_unreachable if va_list did
+       not succeed in being represented as a D type.
+
 2019-08-13  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR middle-end/91421
index 3ebee721a25bbdedbdad8600bf3548f617315cc8..5619ebb1a097c82208f21399ea2e37e7ea2e61e3 100644 (file)
@@ -213,38 +213,54 @@ build_frontend_type (tree type)
       break;
 
     case RECORD_TYPE:
-      if (TYPE_NAME (type))
+    {
+      Identifier *ident = TYPE_IDENTIFIER (type) ?
+       Identifier::idPool (IDENTIFIER_POINTER (TYPE_IDENTIFIER (type))) : NULL;
+
+      /* Neither the `object' and `gcc.builtins' modules will not exist when
+        this is called.  Use a stub 'object' module parent in the meantime.
+        If `gcc.builtins' is later imported, the parent will be overridden
+        with the correct module symbol.  */
+      static Identifier *object = Identifier::idPool ("object");
+      static Module *stubmod = Module::create ("object.d", object, 0, 0);
+
+      StructDeclaration *sdecl = StructDeclaration::create (Loc (), ident,
+                                                           false);
+      sdecl->parent = stubmod;
+      sdecl->structsize = int_size_in_bytes (type);
+      sdecl->alignsize = TYPE_ALIGN_UNIT (type);
+      sdecl->alignment = STRUCTALIGN_DEFAULT;
+      sdecl->sizeok = SIZEOKdone;
+      sdecl->type = (TypeStruct::create (sdecl))->addMod (mod);
+      sdecl->type->ctype = type;
+      sdecl->type->merge2 ();
+
+      sdecl->members = new Dsymbols;
+
+      for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
        {
-         tree structname = DECL_NAME (TYPE_NAME (type));
-         Identifier *ident
-           = Identifier::idPool (IDENTIFIER_POINTER (structname));
-
-         /* Neither the `object' and `gcc.builtins' modules will not exist when
-            this is called.  Use a stub 'object' module parent in the meantime.
-            If `gcc.builtins' is later imported, the parent will be overridden
-            with the correct module symbol.  */
-         static Identifier *object = Identifier::idPool ("object");
-         static Module *stubmod = Module::create ("object.d", object, 0, 0);
-
-         StructDeclaration *sdecl = StructDeclaration::create (Loc (), ident,
-                                                               false);
-         sdecl->parent = stubmod;
-         sdecl->structsize = int_size_in_bytes (type);
-         sdecl->alignsize = TYPE_ALIGN_UNIT (type);
-         sdecl->alignment = STRUCTALIGN_DEFAULT;
-         sdecl->sizeok = SIZEOKdone;
-         sdecl->type = (TypeStruct::create (sdecl))->addMod (mod);
-         sdecl->type->ctype = type;
-         sdecl->type->merge2 ();
-
-         /* Does not seem necessary to convert fields, but the members field
-            must be non-null for the above size setting to stick.  */
-         sdecl->members = new Dsymbols;
-         dtype = sdecl->type;
-         builtin_converted_decls.safe_push (builtin_data (dtype, type, sdecl));
-         return dtype;
+         Type *ftype = build_frontend_type (TREE_TYPE (field));
+         if (!ftype)
+           {
+             delete sdecl->members;
+             return NULL;
+           }
+
+         Identifier *fident
+           = Identifier::idPool (IDENTIFIER_POINTER (DECL_NAME (field)));
+         VarDeclaration *vd = VarDeclaration::create (Loc (), ftype, fident,
+                                                      NULL);
+         vd->offset = tree_to_uhwi (DECL_FIELD_OFFSET (field));
+         vd->semanticRun = PASSsemanticdone;
+         vd->csym = field;
+         sdecl->members->push (vd);
+         sdecl->fields.push (vd);
        }
-      break;
+
+      dtype = sdecl->type;
+      builtin_converted_decls.safe_push (builtin_data (dtype, type, sdecl));
+      return dtype;
+    }
 
     case FUNCTION_TYPE:
       dtype = build_frontend_type (TREE_TYPE (type));
@@ -561,7 +577,7 @@ d_build_builtins_module (Module *m)
       /* Currently, there is no need to run semantic, but we do want to output
         initializers, typeinfo, and others on demand.  */
       Dsymbol *dsym = builtin_converted_decls[i].dsym;
-      if (dsym != NULL)
+      if (dsym != NULL && !dsym->isAnonymous ())
        {
          dsym->parent = m;
          members->push (dsym);
@@ -569,7 +585,18 @@ d_build_builtins_module (Module *m)
     }
 
   /* va_list should already be built, so no need to convert to D type again.  */
-  members->push (build_alias_declaration ("__builtin_va_list", Type::tvalist));
+  StructDeclaration *sd = (Type::tvalist->ty == Tstruct)
+    ? ((TypeStruct *) Type::tvalist)->sym : NULL;
+  if (sd == NULL || !sd->isAnonymous ())
+    {
+      members->push (build_alias_declaration ("__builtin_va_list",
+                                             Type::tvalist));
+    }
+  else
+    {
+      sd->ident = Identifier::idPool ("__builtin_va_list");
+      members->push (sd);
+    }
 
   /* Expose target-specific integer types to the builtins module.  */
   {
@@ -1116,10 +1143,7 @@ d_init_builtins (void)
   /* Build the "standard" abi va_list.  */
   Type::tvalist = build_frontend_type (va_list_type_node);
   if (!Type::tvalist)
-    {
-      error ("cannot represent built-in %<va_list%> type in D");
-      gcc_unreachable ();
-    }
+    sorry ("cannot represent built-in %<va_list%> type in D");
 
   /* Map the va_list type to the D frontend Type.  This is to prevent both
      errors in gimplification or an ICE in targetm.canonical_va_list_type.  */