[llvm] [PAC][IR][AArch64] Add "ptrauth(...)" Constant to represent signed pointers. (PR #85738)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 18:21:48 PDT 2024
================
@@ -4044,6 +4044,60 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
ID.NoCFI = true;
return false;
}
+ case lltok::kw_ptrauth: {
+ // ValID ::= 'ptrauth' '(' ptr @foo ',' i32 <key>
+ // (',' i64 <disc> (',' ptr addrdisc)? )? ')'
+ Lex.Lex();
+
+ Constant *Ptr, *Key;
+ Constant *Disc = nullptr, *AddrDisc = nullptr;
+
+ if (parseToken(lltok::lparen,
+ "expected '(' in constant ptrauth expression") ||
+ parseGlobalTypeAndValue(Ptr) ||
+ parseToken(lltok::comma,
+ "expected comma in constant ptrauth expression") ||
+ parseGlobalTypeAndValue(Key))
+ return true;
+ // If present, parse the optional disc/addrdisc.
+ if (EatIfPresent(lltok::comma))
+ if (parseGlobalTypeAndValue(Disc) ||
+ (EatIfPresent(lltok::comma) && parseGlobalTypeAndValue(AddrDisc)))
+ return true;
+ if (parseToken(lltok::rparen,
+ "expected ')' in constant ptrauth expression"))
+ return true;
+
+ if (!Ptr->getType()->isPointerTy())
+ return error(ID.Loc, "constant ptrauth base pointer must be a pointer");
+
+ auto *KeyC = dyn_cast<ConstantInt>(Key);
+ if (!KeyC || KeyC->getBitWidth() != 32)
+ return error(ID.Loc, "constant ptrauth key must be i32 constant");
+
+ ConstantInt *DiscC = nullptr;
+ if (Disc) {
+ DiscC = dyn_cast<ConstantInt>(Disc);
+ if (!DiscC || DiscC->getBitWidth() != 64)
+ return error(
+ ID.Loc,
+ "constant ptrauth integer discriminator must be i64 constant");
+ } else {
+ DiscC = ConstantInt::get(Type::getInt64Ty(Context), 0);
+ }
+
+ if (AddrDisc) {
+ if (!AddrDisc->getType()->isPointerTy())
+ return error(
+ ID.Loc, "constant ptrauth address discriminator must be a pointer");
+ } else {
+ AddrDisc = ConstantPointerNull::get(PointerType::get(Context, 0));
----------------
nikic wrote:
Okay, I see a test below where this is the case. I guess the question then changes to: Should the default address space of AddrDisc be 0 or the address space of Ptr?
https://github.com/llvm/llvm-project/pull/85738
More information about the llvm-commits
mailing list