On 2/14/25 07:56, Jason Merrill wrote:
External email: Use caution opening links or attachments


On 2/13/25 11:38 AM, Matthew Malcomson wrote:
On 2/12/25 23:30, Jason Merrill wrote:

Shall I make that change?

Please.

Jason


Much simpler patch attached ;-)

Ok for trunk?
From 34bc44d3e491b5db998e4288cba5ae9006a44879 Mon Sep 17 00:00:00 2001
From: Matthew Malcomson <mmalcom...@nvidia.com>
Date: Mon, 10 Feb 2025 16:24:20 +0000
Subject: [PATCH] gcc: testsuite: Fix builtin-speculation-overloads[14].C
 testism

When making warnings trigger a failure in template substitution I
could not find any way to trigger the warning about builtin speculation
not being available on the given target.

Turns out I misread the code -- this warning happens when the
speculation_barrier pattern is not defined.

Here we add an effective target to represent
"__builtin_speculation_safe_value is available on this target" and use
that to adjust our test on SFINAE behaviour accordingly.
N.b. this means that we get extra testing -- not just that things work
on targets which support __builtin_speculation_safe_value, but also that
the behaviour works on targets which don't support it.

Tested with AArch64 native, AArch64 cross compiler, and RISC-V cross
compiler (just running the tests that I've changed).

Ok for trunk?

gcc/testsuite/ChangeLog:

	PR/117991
	* g++.dg/template/builtin-speculation-overloads.def: SUCCESS
	argument in SPECULATION_ASSERTS now uses a macro `true_def`
	instead of the literal `true` for arguments which should work
	with `__builtin_speculation_safe_value`.
	* g++.dg/template/builtin-speculation-overloads1.C: Define
	`true_def` macro on command line to compiler according to the
	effective target representing that
	`__builtin_speculation_safe_value` does something on this
	target.
	* g++.dg/template/builtin-speculation-overloads4.C: Likewise.
	* lib/target-supports.exp
	(check_effective_target_speculation_barrier_defined): New.

Signed-off-by: Matthew Malcomson <mmalcom...@nvidia.com>
---
 .../g++.dg/template/builtin-speculation-overloads.def    | 9 ++++++---
 .../g++.dg/template/builtin-speculation-overloads1.C     | 2 ++
 .../g++.dg/template/builtin-speculation-overloads4.C     | 2 ++
 gcc/testsuite/lib/target-supports.exp                    | 9 +++++++++
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def
index 39d9b748d52..ada13e6f77c 100644
--- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def
+++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def
@@ -15,14 +15,17 @@ class X{};
 class Large { public: int arr[10]; };
 class Incomplete;
 
+/* Using `true_def` in order to account for the fact that if this target
+ * doesn't support __builtin_speculation_safe_value at all everything fails to
+ * substitute.  */
 #define SPECULATION_ASSERTS                                                    \
-  MAKE_SPECULATION_ASSERT (int, true)                                          \
+  MAKE_SPECULATION_ASSERT (int, true_def)                                      \
   MAKE_SPECULATION_ASSERT (float, false)                                       \
   MAKE_SPECULATION_ASSERT (X, false)                                           \
   MAKE_SPECULATION_ASSERT (Large, false)                                       \
   MAKE_SPECULATION_ASSERT (Incomplete, false)                                  \
-  MAKE_SPECULATION_ASSERT (int *, true)                                        \
-  MAKE_SPECULATION_ASSERT (long, true)
+  MAKE_SPECULATION_ASSERT (int *, true_def)                                    \
+  MAKE_SPECULATION_ASSERT (long, true_def)
 
 int main() {
     SPECULATION_ASSERTS
diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C
index bc8f1083a99..4c50d4aa6f5 100644
--- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C
+++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C
@@ -1,5 +1,7 @@
 /* Check that overloaded builtins can be used in templates with SFINAE.  */
 // { dg-do compile { target c++17 } }
+// { dg-additional-options "-Dtrue_def=true" { target speculation_barrier_defined } }
+// { dg-additional-options "-Dtrue_def=false" { target { ! speculation_barrier_defined } } }
 
 /* Checks performed here:
    Various types (some that work, some that don't).  */
diff --git a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C
index c024a21fa18..cc0b3131af7 100644
--- a/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C
+++ b/gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C
@@ -1,5 +1,7 @@
 /* Check that overloaded builtins can be used in templates with SFINAE.  */
 // { dg-do compile { target c++17 } }
+// { dg-additional-options "-Dtrue_def=true" { target speculation_barrier_defined } }
+// { dg-additional-options "-Dtrue_def=false" { target { ! speculation_barrier_defined } } }
 
 /* Checks performed here:
    Optional parameter missing works same as with optional parameter specified.  */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index ff95b88f3c4..0b7abf8379e 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -14304,3 +14304,12 @@ proc check_effective_target_alarm { } {
 	}
     }]
 }
+
+# Return true if a speculation barrier is defined on the target.
+proc check_effective_target_speculation_barrier_defined { } {
+    return [check_no_compiler_messages speculation_barrier_defined assembly {
+	    int main (int argc, char **argv) {
+		return __builtin_speculation_safe_value (argc);
+	    }
+	}]
+}
-- 
2.43.0

Reply via email to