[llvm-branch-commits] [clang] [clang] Define ptrauth_sign_constant builtin. (PR #93904)

Daniil Kovalev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jun 7 03:47:05 PDT 2024


================
@@ -2061,6 +2071,58 @@ ConstantLValueEmitter::VisitCallExpr(const CallExpr *E) {
   }
 }
 
+ConstantLValue
+ConstantLValueEmitter::emitPointerAuthSignConstant(const CallExpr *E) {
+  llvm::Constant *UnsignedPointer = emitPointerAuthPointer(E->getArg(0));
+  unsigned Key = emitPointerAuthKey(E->getArg(1));
+  llvm::Constant *StorageAddress;
+  llvm::Constant *OtherDiscriminator;
+  std::tie(StorageAddress, OtherDiscriminator) =
+      emitPointerAuthDiscriminator(E->getArg(2));
+
+  llvm::Constant *SignedPointer = CGM.getConstantSignedPointer(
+      UnsignedPointer, Key, StorageAddress, OtherDiscriminator);
+  return SignedPointer;
+}
+
+llvm::Constant *ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {
+  Expr::EvalResult Result;
+  bool Succeeded = E->EvaluateAsRValue(Result, CGM.getContext());
+  assert(Succeeded);
+  (void)Succeeded;
+
+  // The assertions here are all checked by Sema.
+  assert(Result.Val.isLValue());
+  return ConstantEmitter(CGM, Emitter.CGF)
+      .emitAbstract(E->getExprLoc(), Result.Val, E->getType());
+}
+
+unsigned ConstantLValueEmitter::emitPointerAuthKey(const Expr *E) {
+  return E->EvaluateKnownConstInt(CGM.getContext()).getZExtValue();
+}
+
+std::pair<llvm::Constant *, llvm::Constant *>
+ConstantLValueEmitter::emitPointerAuthDiscriminator(const Expr *E) {
+  E = E->IgnoreParens();
+
+  if (auto *Call = dyn_cast<CallExpr>(E)) {
----------------
kovdan01 wrote:

```suggestion
  if (const auto *Call = dyn_cast<CallExpr>(E)) {
```

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


More information about the llvm-branch-commits mailing list