]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
hardcfr: make builtin_return tests more portable [PR112334]
authorAlexandre Oliva <oliva@adacore.com>
Fri, 1 Dec 2023 17:31:22 +0000 (14:31 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 1 Dec 2023 17:31:22 +0000 (14:31 -0300)
Rework __builtin_return tests to explicitly call __builtin_apply and
use its return value rather than anything else.  Also require
untyped_assembly.  Avoid the noise out of exceptions escaping the
builtin-applied function, but add a test to cover their effects as
well.

for  gcc/testsuite/ChangeLog

PR target/112334
* c-c++-common/torture/harden-cfr-bret.c: Rework for stricter
untyped_return requirements.  Require untyped_assembly.
* c-c++-common/torture/harden-cfr-bret-except.c: New.
* c-c++-common/torture/harden-cfr-bret-always.c: Require
untyped_assembly.
* c-c++-common/torture/harden-cfr-bret-never.c: Likewise.
* c-c++-common/torture/harden-cfr-bret-noopt.c: Likewise.
* c-c++-common/torture/harden-cfr-bret-noret.c: Likewise.
* c-c++-common/torture/harden-cfr-bret-no-xthrow.c: Likewise.
* c-c++-common/torture/harden-cfr-bret-nothrow.c: Likewise.
* c-c++-common/torture/harden-cfr-bret-retcl.c: Likewise.

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c
gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c

index 779896c60e84615324e26325acec62199d36a899..3406c4e6ef9dc8917418bf21df640d787c1381e2 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even enabling all checks before noreturn calls (leaving
    returning calls enabled), we get checks before __builtin_return without
diff --git a/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c b/gcc/testsuite/c-c++-common/torture/harden-cfr-bret-except.c
new file mode 100644 (file)
index 0000000..3acb61c
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-fharden-control-flow-redundancy -fexceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
+
+/* Check that, with exceptions enabled, even in C, the calls initiated by
+   builtin_apply are enclosed in cleanup handlers that add extra checks.
+   Unfortunately, declaring foobar as nothrow is not enough to avoid the
+   handler around the builtin_apply call, so the other bret tests all use
+   -fno-exceptions.  */
+
+#include "harden-cfr-bret.c"
+
+/* With exceptions, we get an extra check per function, to check before
+   propagating exceptions, so it's 3 in f and 2 in g.  */
+/* { dg-final { scan-tree-dump-times "__hardcfr_check" 5 "hardcfr" } } */
+/* The extra check in g also removes the possibility of inlining the check.  */
+/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */
index 49ce17f5b937c8ae99295d8bb615b6dc0fe3b805..7f8fb64138df13848d314e9221bd28e04b9dd834 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even enabling checks before never noreturn calls (leaving
    returning calls enabled), we get checks before __builtin_return without
index 78e5bf4143927a3d62e64cfa2f17bd11d04b5cf0..07588e8d3c341519939432cbd730f35c2452a2d9 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even enabling checks before no-xthrow-throwing noreturn calls
    (leaving returning calls enabled), we get checks before __builtin_return
index 1512614791ff2dd32737dd7e258054d94d6ec06d..716d9297c8d946d8515f8e096b1486ed5edcc6d3 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even disabling checks before both noreturn and returning
    calls, we still get checks before __builtin_return.  */
index fd95bb7e3e334661a4cac52d3113403604462c13..c6d2baa3120313d5ef5816a07cc5d5814acc758b 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even disabling checks before returning calls (leaving noreturn
    calls enabled), we still get checks before __builtin_return.  */
index c5c361234c499bc0c93b5ce56cb68e528e3b38a1..2fd0d82c7ea3e1d716cbe2b6a2c26a33e104f896 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even enabling checks before nothrow noreturn calls (leaving
    returning calls enabled), we get checks before __builtin_return without
index 137dfbb95d6bbb5933c61367c45ac89c30d1df9e..b070294fde8ade3dbed9d5e2b550a5b78f6b69b7 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
 /* Check that, even disabling checks before noreturn calls (leaving returning
    calls enabled), we still get checks before __builtin_return.  */
index b459ff6b864913c5f9359b1f0c01c103a7e3e697..b6630a6c8669512817bc68b02095ed6ba27cf2d4 100644 (file)
@@ -1,14 +1,27 @@
 /* { dg-do compile } */
-/* { dg-options "-fharden-control-flow-redundancy -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-options "-fharden-control-flow-redundancy -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
+/* { dg-require-effective-target untyped_assembly } */
 
-int f(int i) {
+extern int foobar (void);
+
+#if __cplusplus
+typedef void (*fnt)(...);
+#else
+typedef void (*fnt)();
+#endif
+
+int i;
+
+int f(void) {
   if (i)
-    __builtin_return (&i);
+    __builtin_return (__builtin_apply ((fnt)foobar,
+                                      __builtin_apply_args (), 0));
   return i;
 }
 
-int g(int i) {
-  __builtin_return (&i);
+int g(void) {
+  __builtin_return (__builtin_apply ((fnt)foobar,
+                                    __builtin_apply_args (), 0));
 }
 
 /* Out-of-line checking, before both builtin_return and return in f.  */