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

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 21 13:02:39 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()));
----------------
arsenm wrote:

Relying on the IR function properties feels wrong here, can you detect whether this is indirect from the source context? I'm also not sure IgnoreCallbackUses is correct here (IgnoreAssumeLikeCalls is also potentially questionable) 

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


More information about the llvm-branch-commits mailing list