[clang] [clang] Function type attribute to prevent CFI instrumentation (PR #135836)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Thu May 15 13:59:57 PDT 2025
================
@@ -3006,6 +3006,10 @@ static LValue EmitFunctionDeclLValue(CodeGenFunction &CGF, const Expr *E,
GlobalDecl GD) {
const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
llvm::Constant *V = CGF.CGM.getFunctionPointer(GD);
+ if (E->getType()->isCFIUncheckedCalleeFunctionType()) {
+ if (auto *GV = dyn_cast<llvm::GlobalValue>(V))
+ V = llvm::NoCFIValue::get(GV);
+ }
CharUnits Alignment = CGF.getContext().getDeclAlign(FD);
return CGF.MakeAddrLValue(V, E->getType(), Alignment,
----------------
ilovepi wrote:
since it get's used in the return, you could cache `E->getType()`.
```suggestion
auto ETy = E->getType();
if (ETy->isCFIUncheckedCalleeFunctionType()) {
if (auto *GV = dyn_cast<llvm::GlobalValue>(V))
V = llvm::NoCFIValue::get(GV);
}
CharUnits Alignment = CGF.getContext().getDeclAlign(FD);
return CGF.MakeAddrLValue(V, ETy, Alignment,
```
Feel free to use a better name and explicit type.
https://github.com/llvm/llvm-project/pull/135836
More information about the cfe-commits
mailing list