From: Matthew Malcomson Date: Mon, 10 Feb 2025 16:24:20 +0000 (+0000) Subject: gcc: testsuite: Fix builtin-speculation-overloads[14].C testism X-Git-Tag: basepoints/gcc-16~1966 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9335ff73a509a1f203de691052d600facd07c3f8;p=thirdparty%2Fgcc.git 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 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 --- 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 1599cb96624..9b5fbe52756 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); + } + }] +}