From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 89594385840C; Fri, 3 Mar 2023 00:26:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89594385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677803183; bh=+7oNyFXii9CHnpxGkyYfOQpOFsmqI4bUkHHP8UHG9Gc=; h=From:To:Subject:Date:From; b=WeEP474kKuBfMkd94c3KkpZlebe+AOEFFKDG+B3yUaoJ0d2z56M+aO1m3UCB726NA npm3WRlj4ZlQSuRZ/MGYTr9pFCPJIcLO1sZuhLR205HBNTgrSUr3Tzw3EIH5s4x4lo zmY2W+9du0JiFZYd5OrdABpwjUh+C4TREYLCtuuA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6432] d: Fix ICE on explicit immutable struct import [PR108877] X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/master X-Git-Oldrev: 33a7811896a6c8e6fa71e385dbdf5013d833a116 X-Git-Newrev: ce1cea3e22f58bbddde017f8a92e59bae8892339 Message-Id: <20230303002623.89594385840C@sourceware.org> Date: Fri, 3 Mar 2023 00:26:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ce1cea3e22f58bbddde017f8a92e59bae8892339 commit r13-6432-gce1cea3e22f58bbddde017f8a92e59bae8892339 Author: Iain Buclaw 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. Diff: --- 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(-) 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;