From patchwork Tue Feb 21 14:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 60104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp33912wrd; Tue, 21 Feb 2023 06:19:58 -0800 (PST) X-Google-Smtp-Source: AK7set8RBfjNMOQmpM0/XkQCXgO9Evv3EVathJTdHErGpXTZpc/nnpjB5OBoFFkEOo8ONHv+WFbF X-Received: by 2002:a17:907:d50c:b0:889:ed81:dff7 with SMTP id wb12-20020a170907d50c00b00889ed81dff7mr11576729ejc.9.1676989198203; Tue, 21 Feb 2023 06:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676989198; cv=none; d=google.com; s=arc-20160816; b=sVnECezIj6RC69WrG+S2IoZG5Lqqk1dFxZ5i/ZR16syr/zxpDvVvgDGHS4CcTREhGw KnE/JR9SMnFnUQsRpL+Y8fLMnle/5E+vCb6fWJ6W0F0cwpeXGruRCaSp5ORuaJYzIgBt wm9HY2x1hQ5MwRbXWyP9kYqWw3OnpXnSKSmkWlWW44PktuQFAYLGg0D8VoGROfs1szYh 2y6QB77WTnt+3AAQHcGyEZE0D4U0RnWpTI4naDD5xv+tWW/KxhHAkPabaDASL9SXWjSO ql+bdLcJy6hk1qOp1TnoMuaLJmK3W3u9heGJnHuHueDDiRgAbN5kkSeDNlCJS7pYicWb bEfg== 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=LjjIZaQlKeuZeAH/MtAioYangTrcawLM6xRpCXkZsRQ=; b=v1v6ohph/SgMYpvygLdHh47l4Oui49Roz7kyyAtWRbI2KYzIRzYOmoXAA3oryCH2dC 51gYu8nyaDRzzaMy9hVUnrR1GM/wNj0Fbz28AwtDlYuFGnniV9gheS48ETAivWoHfbJK RwrHX7XXDIx34ZaMS5iuP4itVdQQLHtoW0UeNQhQ3dQQYid4c/3A87VYMhbRqROmV6Bp gW9P+4FM6Zwbgfn4VYc7pW31rAoFx93JLKDibFmtpjSXUo3GQeWYFj22EgqrpzofqTbL RpCpVS+IdH224nX/7a1A1G1rWaB85jEuM0thww4+QjfDT+KV6u7m8yS3BRWF82XzrjX0 uyRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="k7fkqj/M"; 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 ac5-20020a170907344500b008c7c78fee7asi8899467ejc.307.2023.02.21.06.19.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 06:19:58 -0800 (PST) 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="k7fkqj/M"; 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 01F7C385841C for ; Tue, 21 Feb 2023 14:19:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01F7C385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676989197; bh=LjjIZaQlKeuZeAH/MtAioYangTrcawLM6xRpCXkZsRQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=k7fkqj/M2Jk6cbuqQ/rpDTrhOP6fEwzYvXcenl+9UjnrT7EA2+9UnaIvETZ0YkiAY +bRuwBSr1EiCMeQwKqKECys7SwJ8u9cniO3DsuHKPXk5C9BytI4B1WGO/KiIqIz6w/ GIfzXtKDcwlKBxHTw4FDPGWR/RPUduxe7M45a0LM= 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 [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id 2F1ED3858D32 for ; Tue, 21 Feb 2023 14:19:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F1ED3858D32 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4PLhHH3tWtz9sSV; Tue, 21 Feb 2023 15:19:07 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: Set doing_semantic_analysis_p before calling functionSemantic3 Date: Tue, 21 Feb 2023 15:19:00 +0100 Message-Id: <20230221141900.1802009-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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?1758450625551522171?= X-GMAIL-MSGID: =?utf-8?q?1758450625551522171?= Hi, This patch fixes a problem seen where functions which have semantic analysis ran late may still require the use of CTFE built-ins to be evaluated. Bootstrapped and regression tested on x86_64-linux-gnu, committed to mainline. Regards, Iain. --- gcc/d/ChangeLog: * decl.cc (DeclVisitor::visit (FuncDeclaration *)): Set doing_semantic_analysis_p before calling functionSemantic3. gcc/testsuite/ChangeLog: * gdc.dg/ctfeintrinsics.d: New test. --- gcc/d/decl.cc | 4 ++ gcc/testsuite/gdc.dg/ctfeintrinsics.d | 53 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 gcc/testsuite/gdc.dg/ctfeintrinsics.d diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 2bece96f26e..990ac4016b8 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -829,8 +829,12 @@ public: /* Ensure all semantic passes have run. */ if (d->semanticRun < PASS::semantic3) { + gcc_assert (!doing_semantic_analysis_p); + + doing_semantic_analysis_p = true; d->functionSemantic3 (); Module::runDeferredSemantic3 (); + doing_semantic_analysis_p = false; } if (global.errors) diff --git a/gcc/testsuite/gdc.dg/ctfeintrinsics.d b/gcc/testsuite/gdc.dg/ctfeintrinsics.d new file mode 100644 index 00000000000..0e5592b9b1a --- /dev/null +++ b/gcc/testsuite/gdc.dg/ctfeintrinsics.d @@ -0,0 +1,53 @@ +// { dg-do compile { target d_runtime_has_std_library } } + +////////////////////////////////////////////////////// +// std.math.exponential +import std.math.exponential; + +enum test_exp = exp(1.0L); +enum test_expm1 = expm1(1.0L); +enum test_exp2 = exp2(1.0L); +enum test_log = log(1.0L); +enum test_log2 = log2(1.0L); +enum test_log10 = log10(1.0L); +enum test_pow = pow(1.0L, 1L); +enum test_powi = pow(1L, 1L); +enum test_powf = pow(1L, 1.0L); +enum test_powl = pow(1.0L, 1.0L); + +////////////////////////////////////////////////////// +// std.math.operations +import std.math.operations; + +enum test_fmin = fmin(1.0L, 2.0L); +enum test_fmax = fmax(1.0L, 2.0L); +enum test_fma = fma(1.0L, 2.0L, 3.0L); + +////////////////////////////////////////////////////// +// std.math.rounding +import std.math.rounding; + +enum test_round = round(12.34L); +enum test_floorf = floor(12.34f); +enum test_floor = floor(12.34); +enum test_floorl = floor(12.34L); +enum test_ceilf = ceil(12.34f); +enum test_ceil = ceil(12.34); +enum test_ceill = ceil(12.34L); +enum test_trunc = trunc(12.34L); + +////////////////////////////////////////////////////// +// std.math.traits +import std.math.traits; + +enum test_isNaN = isNaN(real.nan); +enum test_isInfinity = isInfinity(real.infinity); +enum test_isFinite = isFinite(1.0L); +enum test_copysign = copysign(1.0L, -1.0L); +enum test_copysigni = copysign(1L, -1.0L); + +////////////////////////////////////////////////////// +// std.math.trigonometry +import std.math.trigonometry; + +enum test_tan = tan(1.0L);