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: 63687 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp143869wrd; Thu, 2 Mar 2023 16:22:52 -0800 (PST) X-Google-Smtp-Source: AK7set9Q1S+eA1fbT6MwAgW5RmcjmJ8XKDaTC58QIJIsc1aV6PEX7RBp1VREhlFMURXwOmgs5Mgy X-Received: by 2002:a17:907:9a9a:b0:908:1164:6358 with SMTP id km26-20020a1709079a9a00b0090811646358mr3886707ejc.21.1677802972710; Thu, 02 Mar 2023 16:22:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677802972; cv=none; d=google.com; s=arc-20160816; b=PryRA0CT6Tpb2NsDsybJGRAqjTq4xtqdwFKEdNmQ2pJVONAFDfFySN1uyEK5waRA71 a45SD1AihVb20ZDYNlf8igWHY7ThykN7qDMFn6kqsU07kdnTxqa8aceTVDVh20It+DWM 1+XYqyZ1hgqiankFxuPc9umIjGpaaT2AKpTwzsGVEf7e0an5quSi7naMGRw23hs9NHJq fuu7bMGdu3kLt6R33v/Ui2fOuiXTaGD5p38A4GJwnlH8cOwVqxFrWKvxorP/VrdSpyaW ucq0/EiWUypAmqos2Sb0g4h2uESVzuRBxl+oZ6huPsY5Y2OB7ZLkfdz7KbnxNFz6jeKz 0wRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=8baC56CUK+D680KsmIvcP9TmEe7umNQU5W3IkUThPuQ=; b=p9i3MikNQcNriBt/0POj9y59St0e3h5e6TXyN0wrrj9QSvxgNvORtGJrU7IAl6Fuvg Esppu/75efpaPmo74/UW3A7UxwfVYA/N5iVcVEyj9vJW5tuFiZhLSE1wcmG4ZvM6NGEu J2AaRPEFzDNQzQGXIiH7BQk7CIcmLnMeqbYlgPS4ISOXGZB+urhjBdjmH6CO51NCJQCw xYEIYNHu7rFdkjCjKrvR1g+Ryu3O35VeZe48zE7TsqVSezMiSD6l6YVBjx4psncvk34H s1Pjx1oUbFgZQY8WEPDGs7Qy+rvnoAu5B4Vvo5pR7T/z9I5yYo8sXhTtF7Ev4+td3yuN sYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KI1Wk6pM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hp10-20020a1709073e0a00b008dd491949d0si868414ejc.12.2023.03.02.16.22.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 16:22:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KI1Wk6pM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B7F83858C5E for ; Fri, 3 Mar 2023 00:22:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B7F83858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677802971; 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=KI1Wk6pM73yIc/5J8Rjr9ktMtQKaimKKOQlTHB+R2ZtDunhvoC4g9rRks7iRhmfvE NRGvUpk5FyXYKQo/TnTFXIBYZNr/vdep5t0x+VdlywwIb/H+W2gRASGMpTJWo2Y/yY B8pz0PY8z/2FX0eMwyUnBPxjvdV6QkQlZB+8foek= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759303930353962333?= X-GMAIL-MSGID: =?utf-8?q?1759303930353962333?= 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;