From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by sourceware.org (Postfix) with ESMTPS id D1AE63858D37 for ; Fri, 3 Mar 2023 00:22:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1AE63858D37 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gdcproject.org Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4PSTDr2xnfz9sSH; Fri, 3 Mar 2023 01:22:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org; s=MBO0001; t=1677802924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8baC56CUK+D680KsmIvcP9TmEe7umNQU5W3IkUThPuQ=; b=GGInw+TXvRRrzXLmeGcZKKli1+kQAFzRYG0tFsWev0PgY+cZYaEJtIlRQqbm8SrdKk3hVk f/v2gpPcVqKPb38HhlHO6yjuhiWbgTKCN8jd7JYDnPLY7bkPzRyl9hPT4sMRD+x9i4KI+c Nhe4tecBUQvfAzl3LSEXWMXoz8Tc8EBLjeA8KFtdIe6yuY+8Fvym/NQyc6lwabZbrdsyAf s5Sk8ZufMF+rwDANIpBrkMvKJqRbg/eSToEygHdrPmrSSgni956NpuXn1/ziA+SDq3Jh5z UKme2JfEzoz37HY1Lit6OUY0pTCBrVCKqqIABmOgd/wV2b3k/X+JIArAGwsCFQ== From: Iain Buclaw To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Fix ICE on explicit immutable struct import [PR10887] Date: Fri, 3 Mar 2023 01:22:02 +0100 Message-Id: <20230303002202.4152119-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --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; -- 2.37.2