[llvm-branch-commits] [clang] callee_type metadata for indirect calls (PR #117036)
Prabhu Rajasekaran via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 22 20:36:12 PDT 2025
================
@@ -2860,9 +2861,25 @@ 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 || !isa<llvm::MDString>(MD->getOperand(1)))
+ return false;
+
+ llvm::MDString *TypeIdStr = cast<llvm::MDString>(MD->getOperand(1));
+ return TypeIdStr->getString().ends_with(".generalized");
+}
+
void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
llvm::Function *F) {
- // Only if we are checking indirect calls.
+ if (CodeGenOpts.CallGraphSection && !HasExistingGeneralizedTypeMD(F) &&
----------------
Prabhuk wrote:
Yes! The CreateFunctionTypeMetadataForIcall function is called twice consistently from:
1. clang::CodeGen::CodeGenModule::SetFunctionAttributes
2. clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition
This leads to multiple instances of !type metadata getting added to the functions.
https://github.com/llvm/llvm-project/pull/117036
More information about the llvm-branch-commits
mailing list