| 1 |
/* { dg-do compile } */ |
| 2 |
/* If configured with --enable-standard-branch-protection, disable it. */ |
| 3 |
/* { dg-additional-options "-mbranch-protection=none" { target { default_branch_protection } } } */ |
| 4 |
|
| 5 |
void f1 (void *); |
| 6 |
void f2 (void *); |
| 7 |
void f3 (void *, void (*)(void *)); |
| 8 |
|
| 9 |
int |
| 10 |
retbr_trampolines (void *a, int b) |
| 11 |
{ |
| 12 |
if (!b) |
| 13 |
{ |
| 14 |
f1 (a); |
| 15 |
return 1; |
| 16 |
} |
| 17 |
if (b) |
| 18 |
{ |
| 19 |
/* Suppress "ISO C forbids nested functions" warning. */ |
| 20 |
_Pragma("GCC diagnostic push") |
| 21 |
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") |
| 22 |
void retbr_tramp_internal (void *c) |
| 23 |
{ |
| 24 |
_Pragma("GCC diagnostic pop") |
| 25 |
if (c == a) |
| 26 |
f2 (c); |
| 27 |
} |
| 28 |
f3 (a, retbr_tramp_internal); |
| 29 |
} |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
__attribute__((target("branch-protection=bti,arch=armv8.3-a"))) |
| 34 |
int |
| 35 |
retbr_trampolines2 (void *a, int b) |
| 36 |
{ |
| 37 |
if (!b) |
| 38 |
{ |
| 39 |
f1 (a); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
if (b) |
| 43 |
{ |
| 44 |
/* Suppress "ISO C forbids nested functions" warning. */ |
| 45 |
_Pragma("GCC diagnostic push") |
| 46 |
_Pragma("GCC diagnostic ignored \"-Wpedantic\"") |
| 47 |
__attribute__((target("branch-protection=bti,arch=armv8.3-a"))) |
| 48 |
void retbr_tramp_internal2 (void *c) |
| 49 |
{ |
| 50 |
_Pragma("GCC diagnostic pop") |
| 51 |
if (c == a) |
| 52 |
f2 (c); |
| 53 |
} |
| 54 |
f3 (a, retbr_tramp_internal2); |
| 55 |
} |
| 56 |
return 0; |
| 57 |
} |
| 58 |
|
| 59 |
/* Trampoline should have BTI C. */ |
| 60 |
/* { dg-final { scan-assembler "\.LTRAMP0:\n\thint\t34" } } */ |