From patchwork Sat Jul 1 15:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 115050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp11116202vqr; Sat, 1 Jul 2023 08:56:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlH4ggW911X/NSHHkDRBg8Jvy0rIkGxPSwtGoG6D4Nk/pEaatiRDSoDliE6iguiOhflOPlL6 X-Received: by 2002:adf:dd0a:0:b0:314:bdb:cf71 with SMTP id a10-20020adfdd0a000000b003140bdbcf71mr6587552wrm.53.1688227009896; Sat, 01 Jul 2023 08:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688227009; cv=none; d=google.com; s=arc-20160816; b=yQvGPJHRMKtQ2IQKN08j+S7QSglZbYHPiGH2vbT/KXlmmuYXhdjmo6j/EgRH4JN+zH PTddaYz7pZf3d7oSI3IzskcIywiC1WbL4TMUUQMtnNQ0F/sWPqx8WLCg9MsKbwFA+jQF /lfP7T2xkC88AWYzWk/dfDvbQ9DfhJ+E+KliBSq+306B/5uP6VLM0JTYaICX+Lf0Zwhu fDoJniEQsrVaKcYtEkio1FVVbKV5drlxKAHahtFBK8kVEDGuqWCE2eWcm/d6JaHciFQS Vng0yG88iIQJDTpX04YCZpJXib9uzVfsnqSj6LLoWFan7GJkm/470J4E+LDB7NZEz9Kq wNtw== 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=6FwRIk9AminDciMyv2IVIcqAH9hwkf5zD32IeiPAjkU=; fh=D2tRalIjW6KCgVuqwFHStdMb9uqe8HSQc2WEvRJ6uLE=; b=US1dVjGK0+PfNLb1SA7UgnK4flPneTw13Rz6NSMpPzPB4xi/8KA6pBxVTCcLAcXRNa 112BEADkJR9Qeo+vGmnJlK0Yp/6ay8HZO1UHbGl2ny+a2stnZywztgpGcS2tAQYD5Tff 1GColl+pYoIp7EGjlV2t4wqJ6YtTMHtJjBec0BO9wix/JsENQf3+xzDFdOa36XW2H59u hswUI5ntEoivxjepm5uOw1aOMr4DxYu78kjtpUmhCz9T4xgLWholmKYk23sx7uvQEiXd 8VCx7dxunUw5/T1uP/mCvkBBYJLw8hBNz4uVuw5/2usoG4oM2I+9+mbbMNM6Ga8As7a9 Jeyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6TI2Yr8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e21-20020aa7d7d5000000b0051da08e2403si6531559eds.255.2023.07.01.08.56.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 08:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z6TI2Yr8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 953AE385843E for ; Sat, 1 Jul 2023 15:56:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 953AE385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688227008; bh=6FwRIk9AminDciMyv2IVIcqAH9hwkf5zD32IeiPAjkU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Z6TI2Yr8XCM/Fm0EcIj7cxognQNbq+eFzIMkxLpr+luU70/KBAveWGTO9JfDT9dya fZRL4AHX1WyXtXTnZk8qZJJTfcaRFVp1WX7AKQWJ1/pJxwjl5NVkXF96FNQsuaO1uM vYe/LtuIQ1g9KOZ+Ret4EsG8DTpHF7Wqod/Gc2QM= 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 A4C453858D38 for ; Sat, 1 Jul 2023 15:56:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4C453858D38 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (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 4QtcH23M9Mz9sjZ; Sat, 1 Jul 2023 17:55:58 +0200 (CEST) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Don't generate code that throws exceptions when compiling with `-fno-exceptions' Date: Sat, 1 Jul 2023 17:55:56 +0200 Message-Id: <20230701155556.2966102-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4QtcH23M9Mz9sjZ X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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?1770234325092430038?= X-GMAIL-MSGID: =?utf-8?q?1770234325092430038?= Hi, The version flags for RTMI, RTTI, and exceptions was unconditionally predefined. These are now only predefined if the feature flag is enabled. It was noticed that there was no `-fexceptions' definition inside d/lang.opt, so the detection of the exceptions option flag was only partially working. Once that was fixed, a few places in the front-end implementation were found to fall fowl of `nothrow' rules, these have been fixed upstream and backported here as well. Bootstrapped and regression tested on x86_64-linux-gnu{-m64,-m32}, committed to mainline, and backported to releases/gcc-13. Regards, Iain. --- Reviewed-on: https://github.com/dlang/dmd/pull/15357 https://github.com/dlang/dmd/pull/15360 PR d/110471 gcc/d/ChangeLog: * d-builtins.cc (d_init_versions): Predefine D_ModuleInfo, D_Exceptions, and D_TypeInfo only if feature is enabled. * lang.opt: Add -fexceptions. gcc/testsuite/ChangeLog: * gdc.dg/pr110471a.d: New test. * gdc.dg/pr110471b.d: New test. * gdc.dg/pr110471c.d: New test. (cherry picked from commit da108c75ad386b3f1f47abb2265296e4b61d578a) --- gcc/d/d-builtins.cc | 9 ++++++--- gcc/d/dmd/root/array.d | 2 +- gcc/d/dmd/semantic2.d | 3 +-- gcc/d/dmd/semantic3.d | 2 +- gcc/d/lang.opt | 4 ++++ gcc/testsuite/gdc.dg/pr110471a.d | 5 +++++ gcc/testsuite/gdc.dg/pr110471b.d | 5 +++++ gcc/testsuite/gdc.dg/pr110471c.d | 5 +++++ 8 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr110471a.d create mode 100644 gcc/testsuite/gdc.dg/pr110471b.d create mode 100644 gcc/testsuite/gdc.dg/pr110471c.d diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc index f40888019ce..60f76fc694c 100644 --- a/gcc/d/d-builtins.cc +++ b/gcc/d/d-builtins.cc @@ -500,9 +500,12 @@ d_init_versions (void) VersionCondition::addPredefinedGlobalIdent ("D_BetterC"); else { - VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo"); - VersionCondition::addPredefinedGlobalIdent ("D_Exceptions"); - VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo"); + if (global.params.useModuleInfo) + VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo"); + if (global.params.useExceptions) + VersionCondition::addPredefinedGlobalIdent ("D_Exceptions"); + if (global.params.useTypeInfo) + VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo"); } if (optimize) diff --git a/gcc/d/dmd/root/array.d b/gcc/d/dmd/root/array.d index 541a12d9e1d..d1c61be7344 100644 --- a/gcc/d/dmd/root/array.d +++ b/gcc/d/dmd/root/array.d @@ -574,7 +574,7 @@ unittest private template arraySortWrapper(T, alias fn) { pragma(mangle, "arraySortWrapper_" ~ T.mangleof ~ "_" ~ fn.mangleof) - extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2) nothrow + extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2) { return fn(cast(const(T*))e1, cast(const(T*))e2); } diff --git a/gcc/d/dmd/semantic2.d b/gcc/d/dmd/semantic2.d index 440e4cbc8e7..ee268d95251 100644 --- a/gcc/d/dmd/semantic2.d +++ b/gcc/d/dmd/semantic2.d @@ -807,9 +807,8 @@ private void doGNUABITagSemantic(ref Expression e, ref Expression* lastTag) // but it's a concession to practicality. // Casts are unfortunately necessary as `implicitConvTo` is not // `const` (and nor is `StringExp`, by extension). - static int predicate(const scope Expression* e1, const scope Expression* e2) nothrow + static int predicate(const scope Expression* e1, const scope Expression* e2) { - scope(failure) assert(0, "An exception was thrown"); return (cast(Expression*)e1).toStringExp().compare((cast(Expression*)e2).toStringExp()); } ale.elements.sort!predicate; diff --git a/gcc/d/dmd/semantic3.d b/gcc/d/dmd/semantic3.d index 33a43187fa8..a912e768f0c 100644 --- a/gcc/d/dmd/semantic3.d +++ b/gcc/d/dmd/semantic3.d @@ -1420,7 +1420,7 @@ private extern(C++) final class Semantic3Visitor : Visitor * https://issues.dlang.org/show_bug.cgi?id=14246 */ AggregateDeclaration ad = ctor.isMemberDecl(); - if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields || global.params.betterC || ctor.type.toTypeFunction.isnothrow) + if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow) return visit(cast(FuncDeclaration)ctor); /* Generate: diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt index 26ca92c4c17..98a95c1dc38 100644 --- a/gcc/d/lang.opt +++ b/gcc/d/lang.opt @@ -291,6 +291,10 @@ fdump-d-original D Display the frontend AST after parsing and semantic passes. +fexceptions +D +; Documented in common.opt + fextern-std= D Joined RejectNegative Enum(extern_stdcpp) Var(flag_extern_stdcpp) -fextern-std= Set C++ name mangling compatibility with . diff --git a/gcc/testsuite/gdc.dg/pr110471a.d b/gcc/testsuite/gdc.dg/pr110471a.d new file mode 100644 index 00000000000..2182f3d5ab2 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr110471a.d @@ -0,0 +1,5 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471 +// { dg-do compile } +// { dg-options "-fno-exceptions" } +version (D_Exceptions) + static assert(0); diff --git a/gcc/testsuite/gdc.dg/pr110471b.d b/gcc/testsuite/gdc.dg/pr110471b.d new file mode 100644 index 00000000000..32562c14f56 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr110471b.d @@ -0,0 +1,5 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471 +// { dg-do compile } +// { dg-options "-fno-moduleinfo" } +version (D_ModuleInfo) + static assert(0); diff --git a/gcc/testsuite/gdc.dg/pr110471c.d b/gcc/testsuite/gdc.dg/pr110471c.d new file mode 100644 index 00000000000..6d13dbaa3fb --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr110471c.d @@ -0,0 +1,5 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471 +// { dg-do compile } +// { dg-options "-fno-rtti" } +version (D_TypeInfo) + static assert(0);