[clang] [clang] Implement function pointer type discrimination (PR #96992)

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 18:42:37 PDT 2024


================
@@ -2220,6 +2220,11 @@ llvm::Constant *ConstantLValueEmitter::emitPointerAuthPointer(const Expr *E) {
 
   // The assertions here are all checked by Sema.
   assert(Result.Val.isLValue());
+  auto *Base = Result.Val.getLValueBase().get<const ValueDecl *>();
+  if (auto *Decl = dyn_cast_or_null<FunctionDecl>(Base)) {
+    assert(Result.Val.getLValueOffset().isZero());
+    return CGM.getRawFunctionPointer(Decl);
----------------
ahatanak wrote:

This function is called to return an unsigned pointer. The returned pointer is used to create a signed pointer for `__builtin_ptrauth_sign_constant` in `emitPointerAuthSignConstant`. `ConstantEmitter` returns a pointer that is signed with zero or a non-zero discriminator that is based on the function type etc.



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


More information about the cfe-commits mailing list