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

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 09:32:12 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:

The checks in `SemaChecking.cpp` and the assertion in `emitPointerAuthPointer` ensure that the expression of the first argument to `__builtin_ptrauth_sign_constant` evaluates to an `LValue` with a `ValueDecl` base. With that restriction, a call to `emitAbstract` returns a signed pointer only when the argument points to a function definition (see `ConstantLValueEmitter::tryEmitBase`). Since we are special-casing functions here, the call to `emitAbstract` returns an unsigned pointer.

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


More information about the cfe-commits mailing list