[llvm-branch-commits] [clang] callee_type metadata for indirect calls (PR #117036)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 22 10:00:05 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) &&
----------------
ilovepi wrote:

Does this *ever* get called on a function that already has metadata? Seems like this code assumes it will only be called on a function once... so I'd guess `hasExistingGeneralizedTypeMD() == false` for all uses of this function. If you're worried, maybe it could be an assert instead? 

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


More information about the llvm-branch-commits mailing list