| 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 |
/* Check that we insert CFR checking so as to not disrupt tail calls. |
| 5 |
Mandatory tail calls are not available in C, and optimizing calls as tail |
| 6 |
calls only takes place after hardcfr, so we insert checking before calls |
| 7 |
followed by copies and return stmts with the same return value, that might |
| 8 |
(or might not) end up optimized to tail calls. */ |
| 9 |
|
| 10 |
extern int g (int i); |
| 11 |
|
| 12 |
int f1(int i) { |
| 13 |
/* Inline check before the returning call. */ |
| 14 |
return g (i); |
| 15 |
} |
| 16 |
|
| 17 |
extern void g2 (int i); |
| 18 |
|
| 19 |
void f2(int i) { |
| 20 |
/* Inline check before the returning call, that ignores the returned value, |
| 21 |
matching the value-less return. */ |
| 22 |
g2 (i); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
void f3(int i) { |
| 27 |
/* Inline check before the returning call. */ |
| 28 |
g (i); |
| 29 |
} |
| 30 |
|
| 31 |
void f4(int i) { |
| 32 |
if (i) |
| 33 |
/* Out-of-line check before the returning call. */ |
| 34 |
return g2 (i); |
| 35 |
/* Out-of-line check before implicit return. */ |
| 36 |
} |
| 37 |
|
| 38 |
int f5(int i) { |
| 39 |
/* Not regarded as a returning call, returning value other than callee's |
| 40 |
returned value. */ |
| 41 |
g (i); |
| 42 |
/* Inline check after the non-returning call. */ |
| 43 |
return i; |
| 44 |
} |
| 45 |
|
| 46 |
/* Out-of-line checks in f4, before returning calls and before return. */ |
| 47 |
/* { dg-final { scan-tree-dump-times "hardcfr_check" 2 "hardcfr" } } */ |
| 48 |
/* Inline checking in all other functions. */ |
| 49 |
/* { dg-final { scan-tree-dump-times "__builtin_trap" 4 "hardcfr" } } */ |
| 50 |
/* Check before tail-call in all but f5, but f4 is out-of-line. */ |
| 51 |
/* { dg-final { scan-tree-dump-times "Inserting inline check before stmt" 3 "hardcfr" } } */ |
| 52 |
/* { dg-final { scan-tree-dump-times "Inserting out-of-line check before stmt" 1 "hardcfr" } } */ |