[llvm-branch-commits] [llvm] [AArch64][PAC] Lower authenticated calls with ptrauth bundles. (PR #85736)

Daniil Kovalev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 22 01:49:13 PDT 2024


================
@@ -1909,9 +1948,60 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
     emitPtrauthAuthResign(MI);
     return;
 
+  case AArch64::BLRA:
+    emitPtrauthBranch(MI);
+    return;
+
   // Tail calls use pseudo instructions so they have the proper code-gen
   // attributes (isCall, isReturn, etc.). We lower them to the real
   // instruction here.
+  case AArch64::AUTH_TCRETURN:
+  case AArch64::AUTH_TCRETURN_BTI: {
+    const uint64_t Key = MI->getOperand(2).getImm();
+    assert(Key < 2 && "Unknown key kind for authenticating tail-call return");
----------------
kovdan01 wrote:

There are many assertions and if statements all around the code which try to check that key is either IA or IB. They look inconsistent: sometimes we have `Key < 2`, sometimes `Key == 0 || Key == 1', sometimes `Key > 1` (for an opposite check). I like the approach from `AArch64AsmPrinter::emitPtrauthBranch`:

```
  assert((Key == AArch64PACKey::IA || Key == AArch64PACKey::IB) &&
         "Invalid auth call key");`
```

It does not rely on magic constants and it's our intentions are clear. The check might be moved to a small helper, it'll be probably more handy to use it everywhere. Please make assertions and if statements checking the key against IA or IB consistent with each other.

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


More information about the llvm-branch-commits mailing list