public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: consteval propagation and templates [PR115986]
@ 2024-07-27 20:26 Jason Merrill
  2024-07-29  7:38 ` [committed] testsuite: Fix up consteval-prop21.C for 32-bit targets [PR115986] Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2024-07-27 20:26 UTC (permalink / raw)
  To: gcc-patches; +Cc: Marek Polacek

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Here the call to e() makes us decide to check d() for escalation at EOF, but
while checking it we try to fold_immediate 0_c, and get confused by the
template trees.  Let's not mess with escalation for function templates.

	PR c++/115986

gcc/cp/ChangeLog:

	* cp-gimplify.cc (remember_escalating_expr): Skip function
	templates.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/consteval-prop21.C: New test.
---
 gcc/cp/cp-gimplify.cc                         |  4 ++++
 gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C

diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc
index e6629dea5fd..6a5e4cf62ca 100644
--- a/gcc/cp/cp-gimplify.cc
+++ b/gcc/cp/cp-gimplify.cc
@@ -53,6 +53,10 @@ static GTY(()) hash_set<tree> *deferred_escalating_exprs;
 static void
 remember_escalating_expr (tree t)
 {
+  if (uses_template_parms (t))
+    /* Templates don't escalate, and cp_fold_immediate can get confused by
+       other template trees in the function body (c++/115986).  */
+    return;
   if (!deferred_escalating_exprs)
     deferred_escalating_exprs = hash_set<tree>::create_ggc (37);
   deferred_escalating_exprs->add (t);
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C b/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
new file mode 100644
index 00000000000..debbda4f425
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
@@ -0,0 +1,17 @@
+// PR c++/115986
+// { dg-do compile { target c++20 } }
+
+template <typename T>
+constexpr int b(T) {
+  return 0;
+}
+consteval __uint128_t operator"" _c(const char*) { return 0; }
+constexpr char e() {
+  long f = true ? 0 : b(long(1));
+  return b(f);
+}
+template <typename>
+void d() {
+  0_c;
+  static_assert(e());
+}

base-commit: 928116e94a5a8a995dffd926af58abfa7286e78e
-- 
2.45.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [committed] testsuite: Fix up consteval-prop21.C for 32-bit targets [PR115986]
  2024-07-27 20:26 [pushed] c++: consteval propagation and templates [PR115986] Jason Merrill
@ 2024-07-29  7:38 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2024-07-29  7:38 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Marek Polacek

On Sat, Jul 27, 2024 at 04:26:07PM -0400, Jason Merrill wrote:
> 	* g++.dg/cpp2a/consteval-prop21.C: New test.

The test fails on 32-bit targets (which don't support __int128 type).
Using unsigned long long instead still ICEs before the fix and passes
after it on those targets.

Tested on x86_64-linux with
GXX_TESTSUITE_STDS=98,11,14,17,20,23,26 make check-g++ RUNTESTFLAGS='--target_board=unix\{-m32,-m64\} dg.exp=consteval-prop21.C'
and committed to trunk as obvious.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-29  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-27 20:26 [pushed] c++: consteval propagation and templates [PR115986] Jason Merrill
2024-07-29  7:38 ` [committed] testsuite: Fix up consteval-prop21.C for 32-bit targets [PR115986] Jakub Jelinek

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).