[llvm] [AArch64][PAC] Protect the entire function if pac-ret+leaf is passed (PR #140895)

Anatoly Trosinenko via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 13:23:39 PDT 2025


================
@@ -74,19 +74,19 @@ define hidden noundef i32 @baz_async(i32 noundef %a) #0 uwtable(async) {
 ; CHECK-V8A-NEXT:    bl _Z3bari
 ; CHECK-V8A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
 ; CHECK-V8A-NEXT:    .cfi_def_cfa_offset 0
+; CHECK-V8A-NEXT:    .cfi_restore w30
 ; CHECK-V8A-NEXT:    hint #29
 ; CHECK-V8A-NEXT:    .cfi_negate_ra_state
-; CHECK-V8A-NEXT:    .cfi_restore w30
 ; CHECK-V8A-NEXT:    b _Z3bari
 ; CHECK-V8A-NEXT:  .LBB1_2: // %if.else
 ; CHECK-V8A-NEXT:    .cfi_restore_state
 ; CHECK-V8A-NEXT:    bl _Z4quuxi
 ; CHECK-V8A-NEXT:    add w0, w0, #1
 ; CHECK-V8A-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
 ; CHECK-V8A-NEXT:    .cfi_def_cfa_offset 0
+; CHECK-V8A-NEXT:    .cfi_restore w30
----------------
atrosinenko wrote:

I tried emitting `.cfi_restore w30` after LR is authenticated in 890100357308c1dc1304e358cad87cc28e50a07e. This adds some complexity but probably not too much. On the other hand, I wonder what would be the correct CFI information when LR is restored by the shrink-wrapped epilogue, but is authenticated near the return (or by retaa/retab), something along the lines:
```
foo:
  paciasp
  ; ... lots of code ...
.LtmpM:
  ; start of prologue
  str x30, [sp, #-16]!
  .cfi_def_cfa_offset 16
  .cfi_offset w30, -16
  ; ...
.LtmpN:
  ; ...
  ldr x30, [sp], #16
  ; end of epilogue
.LtmpK:
  ; ... lots of code ...
  autiasp
  ; is it correct to place both .cfi_restore and .cfi_negate_ra_state here?
  ; should .cfi_restore be placed near ldr x30?
  ; should ldr x30 be moved right before autiasp?
  ret
```

https://github.com/llvm/llvm-project/pull/140895


More information about the llvm-commits mailing list