public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-11235] d: Fix ICE on explicit immutable struct import [PR108877]
Date: Fri,  3 Mar 2023 02:43:34 +0000 (GMT)	[thread overview]
Message-ID: <20230303024334.6AF043858D33@sourceware.org> (raw)

https://gcc.gnu.org/g:c90e68bffa37edd655dd2f5d14bb7b213c9e2431

commit r10-11235-gc90e68bffa37edd655dd2f5d14bb7b213c9e2431
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Mon Feb 27 20:46:18 2023 +0100

    d: Fix ICE on explicit immutable struct import [PR108877]
    
    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.
    
    (cherry picked from commit ce1cea3e22f58bbddde017f8a92e59bae8892339)

Diff:
---
 gcc/d/imports.cc                         | 8 +++++++-
 gcc/testsuite/gdc.dg/imports/pr108877a.d | 6 ++++++
 gcc/testsuite/gdc.dg/pr108877.d          | 9 +++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/d/imports.cc b/gcc/d/imports.cc
index e72f1ea00ac..7852519bf6d 100644
--- a/gcc/d/imports.cc
+++ b/gcc/d/imports.cc
@@ -97,12 +97,17 @@ public:
     tree type = build_ctype (d->type);
     /* Not all kinds of D enums create a TYPE_DECL.  */
     if (TREE_CODE (type) == ENUMERAL_TYPE)
-      d->isym = this->make_import (TYPE_STUB_DECL (type));
+      {
+	type = TYPE_MAIN_VARIANT (type);
+	d->isym = this->make_import (TYPE_STUB_DECL (type));
+      }
+
   }
 
   void visit (AggregateDeclaration *d)
   {
     tree type = build_ctype (d->type);
+    type = TYPE_MAIN_VARIANT (type);
     d->isym = this->make_import (TYPE_STUB_DECL (type));
   }
 
@@ -110,6 +115,7 @@ public:
   {
     /* Want the RECORD_TYPE, not POINTER_TYPE.  */
     tree type = TREE_TYPE (build_ctype (d->type));
+    type = TYPE_MAIN_VARIANT (type);
     d->isym = 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;

                 reply	other threads:[~2023-03-03  2:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230303024334.6AF043858D33@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).