From patchwork Fri Mar 3 00:22:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1751143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=heDsvnLk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PSTFN0yh0z2467 for ; Fri, 3 Mar 2023 11:22:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC2363858C54 for ; Fri, 3 Mar 2023 00:22:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC2363858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677802947; bh=8baC56CUK+D680KsmIvcP9TmEe7umNQU5W3IkUThPuQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=heDsvnLktpEBcbsQcF3hmNBK/k9t0fp8w8AlysnHA4HdjpX+ivUR5Tn5c0f3UxnTh wzdCWyI7OdAkhoAicKmhS2Dq1uXiSWaQPkmeKuPE7VvAGebIObXP4msejpa5WTccPb wxgMzPFCTy+jA8Abu8U+Ktx2WrGL60OoeKa8AXVg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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;