| 1 |
/* PR target/94515. Check .cfi_negate_ra_state with multiple return paths. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-require-effective-target lp64 } */ |
| 4 |
/* { dg-additional-options "-O2 --save-temps" } */ |
| 5 |
|
| 6 |
volatile int zero = 0; |
| 7 |
|
| 8 |
__attribute__((noinline, target("branch-protection=none"))) |
| 9 |
void unwind (void) |
| 10 |
{ |
| 11 |
if (zero == 0) |
| 12 |
throw 42; |
| 13 |
} |
| 14 |
|
| 15 |
__attribute__((noinline, noipa, target("branch-protection=pac-ret"))) |
| 16 |
int test (int z) |
| 17 |
{ |
| 18 |
// paciasp -> cfi_negate_ra_state: RA_no_signing -> RA_signing_SP |
| 19 |
if (z) { |
| 20 |
asm volatile ("":::"x20","x21"); |
| 21 |
unwind (); |
| 22 |
// autiasp -> cfi_negate_ra_state: RA_signing_SP -> RA_no_signing |
| 23 |
return 1; |
| 24 |
} else { |
| 25 |
// 2nd cfi_negate_ra_state because the CFI directives are processed linearily. |
| 26 |
// At this point, the unwinder would believe that the address is not signed |
| 27 |
// due to the previous return. That's why the compiler has to emit second |
| 28 |
// cfi_negate_ra_state to mean that the return address is still signed. |
| 29 |
// cfi_negate_ra_state: RA_no_signing -> RA_signing_SP |
| 30 |
unwind (); |
| 31 |
// autiasp -> cfi_negate_ra_state: RA_signing_SP -> RA_no_signing |
| 32 |
return 2; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
__attribute__((target("branch-protection=none"))) |
| 37 |
int main () |
| 38 |
{ |
| 39 |
try { |
| 40 |
test (zero); |
| 41 |
__builtin_abort (); |
| 42 |
} catch (...) { |
| 43 |
return 0; |
| 44 |
} |
| 45 |
__builtin_abort (); |
| 46 |
} |
| 47 |
|
| 48 |
/* This check only works if there are two return paths in test and |
| 49 |
cfi_negate_ra_state is used for both instead of cfi_remember_state |
| 50 |
plus cfi_restore_state. This is currently the case with -O2. */ |
| 51 |
|
| 52 |
/* { dg-final { scan-assembler-times {\t\.cfi_negate_ra_state\n} 4 } } */ |