[llvm] [AArch64] Handle inttoptr+add+ptrtoint pattern in lowerConstantPtrAuth (PR #189474)

Oskar Wirga via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 17:02:57 PDT 2026


oskarwirga wrote:

> @oskarwirga Just being curious: could you please share a minimal swift reproducer (with compiler invocation command which you use) which results in such a pattern which needs special handling?

After some more investigation, this was indeed a non-standard application of compiler flags/custom toolchain. I encountered this `inttoptr(add(ptrtoint))` pattern when compiling some swift with `-ptrauth-emit-wrapper-globals=false` which emits `ConstantPtrAuth` instead of relying on the `llvm.ptrauth` section. That said, you can reproduce the miscompilation just with LLC:
```llvm
@g = external global i32
@null_signed = constant ptr ptrauth (ptr null, i32 2)
@offset_signed = constant ptr ptrauth (ptr inttoptr (i64 add (i64 ptrtoint (ptr @g to i64), i64 2) to ptr), i32 2)
```

```
llc -mtriple arm64e-apple-darwin -o - repro.ll
```

`@offset_signed` emits `(0)@AUTH(da,0)` instead of the correct `(_g+2)@AUTH(da,0)`.

I've pushed a commit to remove the Swift blame (sorry Swift!) and updated the description to suit. 

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


More information about the llvm-commits mailing list