Skip to content

Commit b8edb81

Browse files
Alexandre OlivaAlexandre Oliva
authored andcommitted
hardcfr: make builtin_return tests more portable [PR112334]
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.
1 parent c4a49eb commit b8edb81

9 files changed

+49
-12
lines changed

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-always.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=always -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even enabling all checks before noreturn calls (leaving
56
returning calls enabled), we get checks before __builtin_return without
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fexceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
4+
5+
/* Check that, with exceptions enabled, even in C, the calls initiated by
6+
builtin_apply are enclosed in cleanup handlers that add extra checks.
7+
Unfortunately, declaring foobar as nothrow is not enough to avoid the
8+
handler around the builtin_apply call, so the other bret tests all use
9+
-fno-exceptions. */
10+
11+
#include "harden-cfr-bret.c"
12+
13+
/* With exceptions, we get an extra check per function, to check before
14+
propagating exceptions, so it's 3 in f and 2 in g. */
15+
/* { dg-final { scan-tree-dump-times "__hardcfr_check" 5 "hardcfr" } } */
16+
/* The extra check in g also removes the possibility of inlining the check. */
17+
/* { dg-final { scan-tree-dump-times "__builtin_trap" 0 "hardcfr" } } */

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-never.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even enabling checks before never noreturn calls (leaving
56
returning calls enabled), we get checks before __builtin_return without

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-no-xthrow.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=no-xthrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even enabling checks before no-xthrow-throwing noreturn calls
56
(leaving returning calls enabled), we get checks before __builtin_return

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noopt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even disabling checks before both noreturn and returning
56
calls, we still get checks before __builtin_return. */

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-noret.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fno-hardcfr-check-returning-calls -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even disabling checks before returning calls (leaving noreturn
56
calls enabled), we still get checks before __builtin_return. */

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-nothrow.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=nothrow -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even enabling checks before nothrow noreturn calls (leaving
56
returning calls enabled), we get checks before __builtin_return without

gcc/testsuite/c-c++-common/torture/harden-cfr-bret-retcl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-noreturn-calls=never -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

45
/* Check that, even disabling checks before noreturn calls (leaving returning
56
calls enabled), we still get checks before __builtin_return. */

gcc/testsuite/c-c++-common/torture/harden-cfr-bret.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
/* { dg-do compile } */
2-
/* { dg-options "-fharden-control-flow-redundancy -fdump-tree-hardcfr -ffat-lto-objects" } */
2+
/* { dg-options "-fharden-control-flow-redundancy -fno-exceptions -fdump-tree-hardcfr -ffat-lto-objects" } */
3+
/* { dg-require-effective-target untyped_assembly } */
34

4-
int f(int i) {
5+
extern int foobar (void);
6+
7+
#if __cplusplus
8+
typedef void (*fnt)(...);
9+
#else
10+
typedef void (*fnt)();
11+
#endif
12+
13+
int i;
14+
15+
int f(void) {
516
if (i)
6-
__builtin_return (&i);
17+
__builtin_return (__builtin_apply ((fnt)foobar,
18+
__builtin_apply_args (), 0));
719
return i;
820
}
921

10-
int g(int i) {
11-
__builtin_return (&i);
22+
int g(void) {
23+
__builtin_return (__builtin_apply ((fnt)foobar,
24+
__builtin_apply_args (), 0));
1225
}
1326

1427
/* Out-of-line checking, before both builtin_return and return in f. */

0 commit comments

Comments
 (0)