public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gdcproject.org>
To: gcc-patches@gcc.gnu.org
Cc: Iain Buclaw <ibuclaw@gdcproject.org>
Subject: [committed] d: Set doing_semantic_analysis_p before calling functionSemantic3
Date: Tue, 21 Feb 2023 15:19:00 +0100	[thread overview]
Message-ID: <20230221141900.1802009-1-ibuclaw@gdcproject.org> (raw)

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);
-- 
2.37.2


                 reply	other threads:[~2023-02-21 14:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230221141900.1802009-1-ibuclaw@gdcproject.org \
    --to=ibuclaw@gdcproject.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).