]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcc: testsuite: Fix builtin-speculation-overloads[14].C testism
authorMatthew Malcomson <mmalcomson@nvidia.com>
Mon, 10 Feb 2025 16:24:20 +0000 (16:24 +0000)
committerMatthew Malcomson <mmalcomson@nvidia.com>
Mon, 17 Feb 2025 11:09:51 +0000 (11:09 +0000)
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 target/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 <mmalcomson@nvidia.com>
gcc/testsuite/g++.dg/template/builtin-speculation-overloads.def
gcc/testsuite/g++.dg/template/builtin-speculation-overloads1.C
gcc/testsuite/g++.dg/template/builtin-speculation-overloads4.C
gcc/testsuite/lib/target-supports.exp

index 39d9b748d52494d9dd1ee7d56bd03ae5514f0d31..ada13e6f77c33ba7711762ec543a2e4d290f2253 100644 (file)
@@ -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
index bc8f1083a994600c08b14c887cc34c91dc04b9c7..4c50d4aa6f5e034d2890cf11dca2902893429198 100644 (file)
@@ -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).  */
index c024a21fa18eb7171a0c8aa83cc9695c5c6670d4..cc0b3131af77128678790a501857aa7417e2c00a 100644 (file)
@@ -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.  */
index 1599cb966249137168b5c7f7de226122649f51c9..9b5fbe527561329026091b3d02419eec38e43470 100644 (file)
@@ -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);
+           }
+       }]
+}