[llvm] [AArch64][PAC] Rework the expansion of AUT/AUTPAC pseudos (PR #169699)

Anatoly Trosinenko via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 10 09:49:24 PDT 2026


================
@@ -2340,46 +2332,80 @@ void AArch64AsmPrinter::emitPtrauthAuthResign(
     break;
   }
 
-  // Compute aut discriminator
-  Register AUTDiscReg =
-      emitPtrauthDiscriminator(AuthSchema.IntDisc, AuthSchema.AddrDisc, Scratch,
-                               AuthSchema.AddrDiscIsKilled);
+  // Checked-but-not-trapping mode ("poison") only applies to resigning,
+  // replace with "unchecked" for standalone AUT.
+  if (!IsResign && ShouldCheck && !ShouldTrap)
+    ShouldCheck = ShouldTrap = false;
 
+  return std::make_pair(ShouldCheck, ShouldTrap);
+}
+
+// We expand AUTx16x17/AUTxMxN into a sequence of the form
+//
+//      ; authenticate Pointer
+//      ; check that Pointer is valid (optional, traps on failure)
+//
+// We expand AUTPAC into a sequence of the form
+//
+//      ; authenticate Pointer
+//      ; check that Pointer is valid (optional, traps on failure)
+//      ; load addend and add it to Pointer (if OptAddend)
+//      ; sign Pointer
+//
+// or
+//
+//      ; authenticate Pointer
+//      ; check that Pointer is valid (skips re-sign on failure)
+//      ; load addend and add it to Pointer (if OptAddend)
+//      ; sign Pointer
+//    Lon_failure:
+//
+void AArch64AsmPrinter::emitPtrauthAuthResign(
+    Register Pointer, Register Scratch, PtrAuthSchema AuthSchema,
+    std::optional<PtrAuthSchema> SignSchema, std::optional<int64_t> Addend,
+    Value *DS) {
+  const bool IsResign = SignSchema.has_value();
+  Register SignAddrDiscOrNone =
+      SignSchema ? SignSchema->AddrDisc : AArch64::NoRegister;
+
+  const auto [ShouldCheck, ShouldTrap] = getCheckAndTrapMode(MF, IsResign);
+  assert((ShouldCheck || !ShouldTrap) && "ShouldTrap implies ShouldCheck");
----------------
atrosinenko wrote:

I tried reusing `enum PtrauthCheckMode` (and dropping its `Default` enumerator, which really means "no command line option was specified") and the code seems to became easier to read, thanks!

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


More information about the llvm-commits mailing list