[llvm-branch-commits] [clang] [clang] callee_type metadata for indirect calls (PR #117036)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 22 13:34:14 PDT 2025
================
@@ -2869,9 +2870,23 @@ static void setLinkageForGV(llvm::GlobalValue *GV, const NamedDecl *ND) {
GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
}
+static bool hasExistingGeneralizedTypeMD(llvm::Function *F) {
+ llvm::MDNode *MD = F->getMetadata(llvm::LLVMContext::MD_type);
+ if (!MD)
+ return false;
+ return MD->hasGeneralizedMDString();
+}
+
void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
llvm::Function *F) {
- // Only if we are checking indirect calls.
+ if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD(F) &&
+ (!F->hasLocalLinkage() ||
+ F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/true,
+ /*IgnoreAssumeLikeCalls=*/true,
+ /*IgnoreLLVMUsed=*/false)))
+ F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType()));
----------------
ilovepi wrote:
Doesn't this function just emit the type metadata if the function *could* be used as an indirect call target? The function name doesn't really communicate that though (at least to me).
Based on that reading, I'd say limiting it to any non-local function (e.g. could be addr taken in another TU) and any local function that has its address taken makes sense for the call-graph use-case.
Or was there some other aspect that concerns you?
https://github.com/llvm/llvm-project/pull/117036
More information about the llvm-branch-commits
mailing list