[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 07:00:34 PST 2025


================
@@ -1549,6 +1549,54 @@ bool Sema::checkConstantPointerAuthKey(Expr *Arg, unsigned &Result) {
   return false;
 }
 
+bool Sema::checkPointerAuthDiscriminatorArg(Expr *Arg,
+                                            PointerAuthDiscArgKind Kind,
+                                            unsigned &IntVal) {
+  if (!Arg) {
+    IntVal = 0;
+    return true;
+  }
+
+  std::optional<llvm::APSInt> Result = Arg->getIntegerConstantExpr(Context);
+  if (!Result) {
+    Diag(Arg->getExprLoc(), diag::err_ptrauth_arg_not_ice);
+    return false;
+  }
+
+  unsigned Max;
+  bool IsAddrDiscArg = false;
+
+  switch (Kind) {
+  case PADAK_AddrDiscPtrAuth:
+    Max = 1;
+    IsAddrDiscArg = true;
+    break;
+  case PADAK_ExtraDiscPtrAuth:
+    Max = PointerAuthQualifier::MaxDiscriminator;
+    break;
+  };
+
+  if (*Result < 0 || *Result > Max) {
+    llvm::SmallString<32> Value;
+    {
+      llvm::raw_svector_ostream str(Value);
+      str << *Result;
+    }
+
----------------
AaronBallman wrote:

I'm pretty sure you can pass an `APSInt` in directly to the call to `Diag()`, but if not, you can get the integer value from the object and pass that in. Let's avoid ostreams if we can.

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


More information about the cfe-commits mailing list