| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fharden-control-flow-redundancy -fdump-tree-hardcfr --param hardcfr-max-blocks=9 --param hardcfr-max-inline-blocks=5 -ffat-lto-objects" } */ |
| 3 |
|
| 4 |
/* Check the instrumentation and the parameters. */ |
| 5 |
|
| 6 |
int |
| 7 |
f (int i, int j) |
| 8 |
{ |
| 9 |
if (i < j) |
| 10 |
return 2 * i; |
| 11 |
else |
| 12 |
return 3 * j; |
| 13 |
} |
| 14 |
|
| 15 |
int |
| 16 |
g (unsigned i, int j) |
| 17 |
{ |
| 18 |
switch (i) |
| 19 |
{ |
| 20 |
case 0: |
| 21 |
return j * 2; |
| 22 |
|
| 23 |
case 1: |
| 24 |
return j * 3; |
| 25 |
|
| 26 |
case 2: |
| 27 |
return j * 5; |
| 28 |
|
| 29 |
default: |
| 30 |
return j * 7; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
h (unsigned i, int j) /* { dg-warning "has more than 9 blocks, the requested maximum" } */ |
| 36 |
{ |
| 37 |
switch (i) |
| 38 |
{ |
| 39 |
case 0: |
| 40 |
return j * 2; |
| 41 |
|
| 42 |
case 1: |
| 43 |
return j * 3; |
| 44 |
|
| 45 |
case 2: |
| 46 |
return j * 5; |
| 47 |
|
| 48 |
case 3: |
| 49 |
return j * 7; |
| 50 |
|
| 51 |
case 4: |
| 52 |
return j * 11; |
| 53 |
|
| 54 |
case 5: |
| 55 |
return j * 13; |
| 56 |
|
| 57 |
case 6: |
| 58 |
return j * 17; |
| 59 |
|
| 60 |
case 7: |
| 61 |
return j * 19; |
| 62 |
|
| 63 |
default: |
| 64 |
return j * 23; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
int |
| 69 |
main (int argc, char *argv[]) |
| 70 |
{ |
| 71 |
if (f (1, 2) != 2 || g (2, 5) != 25 || h (4, 3) != 33 |
| 72 |
|| argc < 0) |
| 73 |
__builtin_abort (); |
| 74 |
/* Call exit, instead of returning, to avoid an edge to the exit block and |
| 75 |
thus implicitly disable hardening of main, when checking before noreturn |
| 76 |
calls is disabled. */ |
| 77 |
__builtin_exit (0); |
| 78 |
} |
| 79 |
|
| 80 |
/* Inlined checking thus trap for f. */ |
| 81 |
/* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "hardcfr" } } */ |
| 82 |
/* Out-of-line checking for g (param), and before both noreturn calls in main. */ |
| 83 |
/* { dg-final { scan-tree-dump-times "__hardcfr_check" 3 "hardcfr" } } */ |
| 84 |
/* No checking for h (too many blocks). */ |