Debian Codegraph @

gcc/testsuite/gcc.dg/torture/harden-cfr-tail-ub.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fharden-control-flow-redundancy -fhardcfr-check-returning-calls -fno-hardcfr-check-exceptions -fdump-tree-hardcfr -ffat-lto-objects -Wno-return-type" } */
3
4 /* In C only, check some additional cases (comparing with
5 c-c++-common/torture/harden-cfr-tail.c) of falling off the end of non-void
6 function. C++ would issue an unreachable call in these cases. */
7
8 extern int g (int i);
9
10 int f1(int i) {
11 /* Inline check before the returning call, that doesn't return anything. */
12 g (i);
13 /* Implicit return without value, despite the return type; this combination
14 enables tail-calling of g, and is recognized as a returning call. */
15 }
16
17 extern void g2 (int i);
18
19 int f2(int i) {
20 /* Inline check before the returning call, that disregards its return
21 value. */
22 g2 (i);
23 /* Implicit return without value, despite the return type; this combination
24 enables tail-calling of g2, and is recognized as a returning call. */
25 }
26
27 int f3(int i) {
28 if (i)
29 /* Out-of-line check before the returning call. */
30 return g (i);
31 /* Out-of-line check before implicit return. */
32 }
33
34 /* Out-of-line checks in f3, before returning calls and before return. */
35 /* { dg-final { scan-tree-dump-times "hardcfr_check" 2 "hardcfr" } } */
36 /* Inline checking in all other functions. */
37 /* { dg-final { scan-tree-dump-times "__builtin_trap" 2 "hardcfr" } } */
38 /* Check before tail-call in all functions, but f3 is out-of-line. */
39 /* { dg-final { scan-tree-dump-times "Inserting inline check before stmt" 2 "hardcfr" } } */
40 /* { dg-final { scan-tree-dump-times "Inserting out-of-line check before stmt" 1 "hardcfr" } } */