]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Fix ICE on explicit immutable struct import [PR108877]
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 27 Feb 2023 19:46:18 +0000 (20:46 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Fri, 3 Mar 2023 00:25:32 +0000 (01:25 +0100)
Const and immutable types are built as variants of the type they are
derived from, and TYPE_STUB_DECL is not set for these variants.

PR d/108877

gcc/d/ChangeLog:

* imports.cc (ImportVisitor::visit (EnumDeclaration *)): Call
make_import on TYPE_MAIN_VARIANT.
(ImportVisitor::visit (AggregateDeclaration *)): Likewise.
(ImportVisitor::visit (ClassDeclaration *)): Likewise.

gcc/testsuite/ChangeLog:

* gdc.dg/imports/pr108877a.d: New test.
* gdc.dg/pr108877.d: New test.

gcc/d/imports.cc
gcc/testsuite/gdc.dg/imports/pr108877a.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr108877.d [new file with mode: 0644]

index 3b46d1b75609f708c7cc027d95f12afc79460aaf..2efef4ed54f437163f673412ddfc55fb13c3b4d2 100644 (file)
@@ -106,12 +106,16 @@ public:
     tree type = build_ctype (d->type);
     /* Not all kinds of D enums create a TYPE_DECL.  */
     if (TREE_CODE (type) == ENUMERAL_TYPE)
-      this->result_ = this->make_import (TYPE_STUB_DECL (type));
+      {
+       type = TYPE_MAIN_VARIANT (type);
+       this->result_ = this->make_import (TYPE_STUB_DECL (type));
+      }
   }
 
   void visit (AggregateDeclaration *d) final override
   {
     tree type = build_ctype (d->type);
+    type = TYPE_MAIN_VARIANT (type);
     this->result_ = this->make_import (TYPE_STUB_DECL (type));
   }
 
@@ -119,6 +123,7 @@ public:
   {
     /* Want the RECORD_TYPE, not POINTER_TYPE.  */
     tree type = TREE_TYPE (build_ctype (d->type));
+    type = TYPE_MAIN_VARIANT (type);
     this->result_ = this->make_import (TYPE_STUB_DECL (type));
   }
 
diff --git a/gcc/testsuite/gdc.dg/imports/pr108877a.d b/gcc/testsuite/gdc.dg/imports/pr108877a.d
new file mode 100644 (file)
index 0000000..a23c78d
--- /dev/null
@@ -0,0 +1,6 @@
+immutable struct ImmutableS { }
+const struct ConstS { }
+immutable class ImmutableC { }
+const class ConstC { }
+immutable enum ImmutableE { _ }
+const enum ConstE { _ }
diff --git a/gcc/testsuite/gdc.dg/pr108877.d b/gcc/testsuite/gdc.dg/pr108877.d
new file mode 100644 (file)
index 0000000..710551f
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-options "-I $srcdir/gdc.dg" }
+// { dg-do compile }
+import imports.pr108877a :
+    ImmutableS,
+    ConstS,
+    ImmutableC,
+    ConstC,
+    ImmutableE,
+    ConstE;