diff mbox series

[committed] d: Fix ICE on explicit immutable struct import [PR10887]

Message ID 20230303002202.4152119-1-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] d: Fix ICE on explicit immutable struct import [PR10887] | expand

Commit Message

Iain Buclaw March 3, 2023, 12:22 a.m. UTC
Hi,

This patch fixes an ICE in the D front-end when importing an immutable
struct.  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.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, committed
to mainline, and backported to the release branches for gcc-10, gcc-11,
and gcc-12.

Regards,
Iain.

---
	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                         | 7 ++++++-
 gcc/testsuite/gdc.dg/imports/pr108877a.d | 6 ++++++
 gcc/testsuite/gdc.dg/pr108877.d          | 9 +++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/imports/pr108877a.d
 create mode 100644 gcc/testsuite/gdc.dg/pr108877.d
diff mbox series

Patch

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index 3b46d1b7560..2efef4ed54f 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -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
index 00000000000..a23c78ddf84
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/imports/pr108877a.d
@@ -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
index 00000000000..710551f3f9a
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr108877.d
@@ -0,0 +1,9 @@ 
+// { dg-options "-I $srcdir/gdc.dg" }
+// { dg-do compile }
+import imports.pr108877a :
+    ImmutableS,
+    ConstS,
+    ImmutableC,
+    ConstC,
+    ImmutableE,
+    ConstE;