https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/204266

>From d9350077f8146cf43ec702be2d386614e88c1966 Mon Sep 17 00:00:00 2001
From: prabhukr <[email protected]>
Date: Tue, 16 Jun 2026 16:15:50 -0700
Subject: [PATCH 1/2] Uncorrelate CFI and Callgraph related type metadata
 annotations

Note: This patch will be broken into separate smaller patches for clang
and llvm after discussion.

When -fexperimental-call-graph-section flag is set, it adds type
metadata to all the functions whose addresses are taken and does not
have local linkage. When this flag is set along with CFI, the type
metadata is added to all the vtable functions including destructors.
This changes which functions are to be treated as CFI functions and
includes such vtable entries to become part of the CFI check jumptables.

To disambiguate intentions of CFI and callgraph mechanisms, this patch
renames metadata set by callgraph mechanism to !callgraph
(MD_callgraph). This prevents inflating the list of CFI functions when
callgraph section is enabled along with CFI.
---
 clang/lib/CodeGen/CodeGenModule.cpp           | 14 +++++++------
 .../CodeGen/call-graph-section-callback.cpp   |  2 +-
 .../CodeGen/call-graph-section-templates.cpp  | 16 +++++++--------
 .../call-graph-section-virtual-methods.cpp    |  4 ++--
 clang/test/CodeGen/call-graph-section.c       | 14 ++++++-------
 clang/test/CodeGen/call-graph-section.cpp     | 20 +++++++++----------
 llvm/include/llvm/IR/FixedMetadataKinds.def   |  2 ++
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp    |  2 +-
 llvm/lib/IR/Metadata.cpp                      |  6 +++---
 .../Transforms/IPO/ThinLTOBitcodeWriter.cpp   | 15 ++++++++++++++
 .../ARM/call-graph-section-addrtaken.ll       |  6 +++---
 .../ARM/call-graph-section-tailcall.ll        |  8 ++++----
 .../X86/call-graph-section-addrtaken.ll       |  6 +++---
 .../X86/call-graph-section-tailcall.ll        |  8 ++++----
 14 files changed, 71 insertions(+), 52 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 41049d85121be..25675f99258b4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3395,17 +3395,19 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function 
*F) {
 
 void CodeGenModule::createIndirectFunctionTypeMD(const FunctionDecl *FD,
                                                  llvm::Function *F) {
-  // Return if generalized type metadata is already attached.
-  if (hasExistingGeneralizedTypeMD(F))
-    return;
-
   // All functions which are not internal linkage could be indirect targets.
   // Address taken functions with internal linkage could be indirect targets.
   if (!F->hasLocalLinkage() ||
       F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/true,
                                        /*IgnoreAssumeLikeCalls=*/true,
-                                       /*IgnoreLLVMUsed=*/false))
-    F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType()));
+                                       /*IgnoreLLVMUsed=*/false)) {
+    F->addMetadata(llvm::LLVMContext::MD_callgraph,
+                   *llvm::MDTuple::get(
+                       getLLVMContext(),
+                       {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+                            llvm::Type::getInt64Ty(getLLVMContext()), 0)),
+                        CreateMetadataIdentifierGeneralized(FD->getType())}));
+  }
 }
 
 void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
diff --git a/clang/test/CodeGen/call-graph-section-callback.cpp 
b/clang/test/CodeGen/call-graph-section-callback.cpp
index e9b0a1818e3a4..080fa07e41847 100644
--- a/clang/test/CodeGen/call-graph-section-callback.cpp
+++ b/clang/test/CodeGen/call-graph-section-callback.cpp
@@ -10,7 +10,7 @@ typedef void (*CallbackFn)(int);
 
 // Callback function with "internal" linkage.
 // CHECK-LABEL: define internal void @_ZL10myCallbacki(
-// CHECK-SAME: {{.*}} !type [[F_CALLBACK:![0-9]+]]
+// CHECK-SAME: {{.*}} !callgraph [[F_CALLBACK:![0-9]+]]
 static void myCallback(int value) 
 {
     volatile int sink = value;
diff --git a/clang/test/CodeGen/call-graph-section-templates.cpp 
b/clang/test/CodeGen/call-graph-section-templates.cpp
index 39030d27a4ea9..e6c43a41a86ab 100644
--- a/clang/test/CodeGen/call-graph-section-templates.cpp
+++ b/clang/test/CodeGen/call-graph-section-templates.cpp
@@ -17,27 +17,27 @@ template <class T>
 class Cls2 {
 public:
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f1Ev(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F1:![0-9]+]]
   void f1() {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f2ES0_(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F2:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F2:![0-9]+]]
   void f2(T a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f3EPS0_(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F3:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F3:![0-9]+]]
   void f3(T *a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f4EPKS0_(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F4:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F4:![0-9]+]]
   void f4(const T *a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f5ERS0_(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F5:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F5:![0-9]+]]
   void f5(T &a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls2I4Cls1E2f6ERKS0_(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F6:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F6:![0-9]+]]
   void f6(const T &a) {}
 
   // Mixed type function pointer member
@@ -58,7 +58,7 @@ template <class T>
 T *T_func(T a, T *b, const T *c, T &d, const T &e) { return b; }
 
 // CST-LABEL: define {{.*}} @_Z3foov
-// CST-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]]
+// CST-SAME: {{.*}} !callgraph [[F_TCLS2F1:![0-9]+]]
 void foo() {
   // Methods for Cls2<Cls1> is checked above within the template description.
   Cls2<Cls1> Obj;
@@ -99,7 +99,7 @@ void foo() {
 }
 
 // CST-LABEL: define {{.*}} @_Z6T_funcI4Cls1EPT_S1_S2_PKS1_RS1_RS3_(
-// CST-SAME: {{.*}} !type [[F_TFUNC_CLS1:![0-9]+]]
+// CST-SAME: {{.*}} !callgraph [[F_TFUNC_CLS1:![0-9]+]]
 
 // CST: [[F_TCLS2F1]] = !{i64 0, !"_ZTSFvvE.generalized"}
 // CST: [[F_TFUNC_CLS1_CT]] = !{[[F_TFUNC_CLS1:![0-9]+]]}
diff --git a/clang/test/CodeGen/call-graph-section-virtual-methods.cpp 
b/clang/test/CodeGen/call-graph-section-virtual-methods.cpp
index afeeae146ec41..7aa7a8cf740ea 100644
--- a/clang/test/CodeGen/call-graph-section-virtual-methods.cpp
+++ b/clang/test/CodeGen/call-graph-section-virtual-methods.cpp
@@ -12,13 +12,13 @@
 class Base {
   public:
     // FT-LABEL: define {{.*}} @_ZN4Base2vfEPc(
-    // FT-SAME: {{.*}} !type [[F_TVF:![0-9]+]]
+    // FT-SAME: {{.*}} !callgraph [[F_TVF:![0-9]+]]
     virtual int vf(char *a) { return 0; };
   };
   
   class Derived : public Base {
   public:
-    // FT: define {{.*}} @_ZN7Derived2vfEPc({{.*}} !type [[F_TVF]]
+    // FT: define {{.*}} @_ZN7Derived2vfEPc({{.*}} !callgraph [[F_TVF]]
     int vf(char *a) override { return 1; };
   };
   
diff --git a/clang/test/CodeGen/call-graph-section.c 
b/clang/test/CodeGen/call-graph-section.c
index 69cdd59549190..9d8e99a9ad098 100644
--- a/clang/test/CodeGen/call-graph-section.c
+++ b/clang/test/CodeGen/call-graph-section.c
@@ -7,12 +7,12 @@
 // RUN: -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK,MS %s
 
 // CHECK-LABEL: define {{(dso_local)?}} void @foo(
-// CHECK-SAME: {{.*}} !type [[F_TVOID:![0-9]+]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TVOID:![0-9]+]]
 void foo() {
 }
 
 // CHECK-LABEL: define {{(dso_local)?}} void @bar(
-// CHECK-SAME: {{.*}} !type [[F_TVOID]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TVOID]]
 void bar() {
   void (*fp)() = foo;
   // ITANIUM: call {{.*}}, !callee_type [[F_TVOID_CT:![0-9]+]]
@@ -21,19 +21,19 @@ void bar() {
 }
 
 // CHECK-LABEL: define {{(dso_local)?}} i32 @baz(
-// CHECK-SAME: {{.*}} !type [[F_TPRIMITIVE:![0-9]+]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TPRIMITIVE:![0-9]+]]
 int baz(char a, float b, double c) {
   return 1;
 }
 
 // CHECK-LABEL: define {{(dso_local)?}} ptr @qux(
-// CHECK-SAME: {{.*}} !type [[F_TPTR:![0-9]+]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TPTR:![0-9]+]]
 int *qux(char *a, float *b, double *c) {
   return 0;
 }
 
 // CHECK-LABEL: define {{(dso_local)?}} void @corge(
-// CHECK-SAME: {{.*}} !type [[F_TVOID]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TVOID]]
 void corge() {
   int (*fp_baz)(char, float, double) = baz;  
   // CHECK: call i32 {{.*}}, !callee_type [[F_TPRIMITIVE_CT:![0-9]+]]
@@ -53,11 +53,11 @@ struct st2 {
 };
 
 // CHECK-LABEL: define {{(dso_local)?}} void @stparam(
-// CHECK-SAME: {{.*}} !type [[F_TSTRUCT:![0-9]+]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TSTRUCT:![0-9]+]]
 void stparam(struct st2 a, struct st2 *b) {}
 
 // CHECK-LABEL: define {{(dso_local)?}} void @stf(
-// CHECK-SAME: {{.*}} !type [[F_TVOID]]
+// CHECK-SAME: {{.*}} !callgraph [[F_TVOID]]
 void stf() {
   struct st1 St1;
   St1.fp = qux;  
diff --git a/clang/test/CodeGen/call-graph-section.cpp 
b/clang/test/CodeGen/call-graph-section.cpp
index 86ed3ee2337a7..5265eda31ccf9 100644
--- a/clang/test/CodeGen/call-graph-section.cpp
+++ b/clang/test/CodeGen/call-graph-section.cpp
@@ -12,7 +12,7 @@
 class Cls1 {
 public:
   // FT-LABEL: define {{.*}} ptr @_ZN4Cls18receiverEPcPf(
-  // FT-SAME: {{.*}} !type [[F_TCLS1RECEIVER:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS1RECEIVER:![0-9]+]]
   static int *receiver(char *a, float *b) { return 0; }
 };
 
@@ -21,39 +21,39 @@ class Cls2 {
   int *(*fp)(char *, float *);
 
   // FT-LABEL: define {{.*}} i32 @_ZN4Cls22f1Ecfd(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F1:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F1:![0-9]+]]
   int f1(char a, float b, double c) { return 0; }
 
   // FT-LABEL: define {{.*}} ptr @_ZN4Cls22f2EPcPfPd(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F2:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F2:![0-9]+]]
   int *f2(char *a, float *b, double *c) { return 0; }
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f3E4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F3F4:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F3F4:![0-9]+]]
   void f3(Cls1 a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f4E4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F3F4]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F3F4]]
   void f4(const Cls1 a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f5EP4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F5:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F5:![0-9]+]]
   void f5(Cls1 *a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f6EPK4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F6:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F6:![0-9]+]]
   void f6(const Cls1 *a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f7ER4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F7:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F7:![0-9]+]]
   void f7(Cls1 &a) {}
 
   // FT-LABEL: define {{.*}} void @_ZN4Cls22f8ERK4Cls1(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F8:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F8:![0-9]+]]
   void f8(const Cls1 &a) {}
 
   // FT-LABEL: define {{.*}} void @_ZNK4Cls22f9Ev(
-  // FT-SAME: {{.*}} !type [[F_TCLS2F9:![0-9]+]]
+  // FT-SAME: {{.*}} !callgraph [[F_TCLS2F9:![0-9]+]]
   void f9() const {}
 };
 
diff --git a/llvm/include/llvm/IR/FixedMetadataKinds.def 
b/llvm/include/llvm/IR/FixedMetadataKinds.def
index 552c1f60f2d38..a6c8d84b56ce5 100644
--- a/llvm/include/llvm/IR/FixedMetadataKinds.def
+++ b/llvm/include/llvm/IR/FixedMetadataKinds.def
@@ -64,3 +64,5 @@ LLVM_FIXED_MD_KIND(MD_inline_history, "inline_history", 49)
 LLVM_FIXED_MD_KIND(MD_elf_section_properties, "elf_section_properties", 50)
 LLVM_FIXED_MD_KIND(MD_unique_id, "guid", 51)
 LLVM_FIXED_MD_KIND(MD_mem_cache_hint, "mem.cache_hint", 52)
+LLVM_FIXED_MD_KIND(MD_callgraph, "callgraph", 53)
+
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index cdb9d760606f6..84efbff3de598 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1756,7 +1756,7 @@ void AsmPrinter::emitStackUsage(const MachineFunction 
&MF) {
 /// type metadata. Returns null if metadata cannot be found.
 static ConstantInt *extractNumericCGTypeId(const Function &F) {
   SmallVector<MDNode *, 2> Types;
-  F.getMetadata(LLVMContext::MD_type, Types);
+  F.getMetadata(LLVMContext::MD_callgraph, Types);
   for (const auto &Type : Types) {
     if (Type->hasGeneralizedMDString()) {
       MDString *MDGeneralizedTypeId = cast<MDString>(Type->getOperand(1));
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 491c788fc4445..0194b8f0a2083 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -1891,14 +1891,14 @@ void GlobalObject::copyMetadata(const GlobalObject 
*Other, unsigned Offset) {
   Other->getAllMetadata(MDs);
   for (auto &MD : MDs) {
     // We need to adjust the type metadata offset.
-    if (Offset != 0 && MD.first == LLVMContext::MD_type) {
+    if (Offset != 0 && (MD.first == LLVMContext::MD_type ||
+                        MD.first == LLVMContext::MD_callgraph)) {
       auto *OffsetConst = cast<ConstantInt>(
           cast<ConstantAsMetadata>(MD.second->getOperand(0))->getValue());
       Metadata *TypeId = MD.second->getOperand(1);
       auto *NewOffsetMD = ConstantAsMetadata::get(ConstantInt::get(
           OffsetConst->getType(), OffsetConst->getValue() + Offset));
-      addMetadata(LLVMContext::MD_type,
-                  *MDNode::get(getContext(), {NewOffsetMD, TypeId}));
+      addMetadata(MD.first, *MDNode::get(getContext(), {NewOffsetMD, TypeId}));
       continue;
     }
     // If an offset adjustment was specified we need to modify the DIExpression
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp 
b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index c14c9b869525d..01a0f3385a3c0 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -169,6 +169,21 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
           LLVMContext::MD_type,
           *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
     }
+
+    SmallVector<MDNode *, 1> CGMDs;
+    GO.getMetadata(LLVMContext::MD_callgraph, CGMDs);
+
+    GO.eraseMetadata(LLVMContext::MD_callgraph);
+    for (auto *MD : CGMDs) {
+      auto I = LocalToGlobal.find(MD->getOperand(1));
+      if (I == LocalToGlobal.end()) {
+        GO.addMetadata(LLVMContext::MD_callgraph, *MD);
+        continue;
+      }
+      GO.addMetadata(
+          LLVMContext::MD_callgraph,
+          *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
+    }
   }
 }
 
diff --git a/llvm/test/CodeGen/ARM/call-graph-section-addrtaken.ll 
b/llvm/test/CodeGen/ARM/call-graph-section-addrtaken.ll
index 9e243aec1128d..8bb9230316288 100644
--- a/llvm/test/CodeGen/ARM/call-graph-section-addrtaken.ll
+++ b/llvm/test/CodeGen/ARM/call-graph-section-addrtaken.ll
@@ -5,16 +5,16 @@
 
 ; RUN: llc -mtriple=arm-unknown-linux --call-graph-section -o - < %s | 
FileCheck %s
 
-declare !type !0 void @_Z6doWorkPFviE(ptr)
+declare !callgraph !0 void @_Z6doWorkPFviE(ptr)
 
-define i32 @_Z4testv() !type !1 {
+define i32 @_Z4testv() !callgraph !1 {
 entry:
   call void @_Z6doWorkPFviE(ptr nonnull @_ZL10myCallbacki)
   ret i32 0
 }
 
 ; CHECK: _ZL10myCallbacki:
-define internal void @_ZL10myCallbacki(i32 %value) !type !2 {
+define internal void @_ZL10myCallbacki(i32 %value) !callgraph !2 {
 entry:
   %sink = alloca i32, align 4
   store volatile i32 %value, ptr %sink, align 4
diff --git a/llvm/test/CodeGen/ARM/call-graph-section-tailcall.ll 
b/llvm/test/CodeGen/ARM/call-graph-section-tailcall.ll
index 35e570bdde405..c6152ef7c732b 100644
--- a/llvm/test/CodeGen/ARM/call-graph-section-tailcall.ll
+++ b/llvm/test/CodeGen/ARM/call-graph-section-tailcall.ll
@@ -3,13 +3,13 @@
 ; RUN: llc -mtriple=arm-unknown-linux --call-graph-section -filetype=obj -o - 
< %s | \
 ; RUN: llvm-readelf -x .llvm.callgraph - | FileCheck %s
 
-define i32 @check_tailcall(ptr %func, i8 %x) !type !0 {
+define i32 @check_tailcall(ptr %func, i8 %x) !callgraph !0 {
 entry:
   %call = tail call i32 %func(i8 signext %x), !callee_type !1
   ret i32 %call
 }
 
-define i32 @main(i32 %argc) !type !3 {
+define i32 @main(i32 %argc) !callgraph !3 {
 entry:
   %andop = and i32 %argc, 1
   %cmp = icmp eq i32 %andop, 0
@@ -18,9 +18,9 @@ entry:
   ret i32 %call.i
 }
 
-declare !type !2 i32 @foo(i8 signext)
+declare !callgraph !2 i32 @foo(i8 signext)
 
-declare !type !2 i32 @bar(i8 signext)
+declare !callgraph !2 i32 @bar(i8 signext)
 
 !0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
 !1 = !{!2}
diff --git a/llvm/test/CodeGen/X86/call-graph-section-addrtaken.ll 
b/llvm/test/CodeGen/X86/call-graph-section-addrtaken.ll
index ab8498d8d3451..42d46e005fce5 100644
--- a/llvm/test/CodeGen/X86/call-graph-section-addrtaken.ll
+++ b/llvm/test/CodeGen/X86/call-graph-section-addrtaken.ll
@@ -5,16 +5,16 @@
 
 ; RUN: llc -mtriple=x86_64-unknown-linux --call-graph-section -o - < %s | 
FileCheck %s
 
-declare !type !0 void @_Z6doWorkPFviE(ptr)
+declare !callgraph !0 void @_Z6doWorkPFviE(ptr)
 
-define i32 @_Z4testv() !type !1 {
+define i32 @_Z4testv() !callgraph !1 {
 entry:
   call void @_Z6doWorkPFviE(ptr nonnull @_ZL10myCallbacki)
   ret i32 0
 }
 
 ; CHECK: _ZL10myCallbacki:
-define internal void @_ZL10myCallbacki(i32 %value) !type !2 {
+define internal void @_ZL10myCallbacki(i32 %value) !callgraph !2 {
 entry:
   %sink = alloca i32, align 4
   store volatile i32 %value, ptr %sink, align 4
diff --git a/llvm/test/CodeGen/X86/call-graph-section-tailcall.ll 
b/llvm/test/CodeGen/X86/call-graph-section-tailcall.ll
index 49cc335bf7379..7246a02003445 100644
--- a/llvm/test/CodeGen/X86/call-graph-section-tailcall.ll
+++ b/llvm/test/CodeGen/X86/call-graph-section-tailcall.ll
@@ -6,13 +6,13 @@
 ; RUN: llc -mtriple=x86_64-unknown-linux --call-graph-section -filetype=obj -o 
- < %s | \
 ; RUN: llvm-readelf -x .llvm.callgraph - | FileCheck %s
 
-define i32 @check_tailcall(ptr %func, i8 %x) !type !0 {
+define i32 @check_tailcall(ptr %func, i8 %x) !callgraph !0 {
 entry:
   %call = tail call i32 %func(i8 signext %x), !callee_type !1
   ret i32 %call
 }
 
-define i32 @main(i32 %argc) !type !3 {
+define i32 @main(i32 %argc) !callgraph !3 {
 entry:
   %andop = and i32 %argc, 1
   %cmp = icmp eq i32 %andop, 0
@@ -21,9 +21,9 @@ entry:
   ret i32 %call.i
 }
 
-declare !type !2 i32 @foo(i8 signext)
+declare !callgraph !2 i32 @foo(i8 signext)
 
-declare !type !2 i32 @bar(i8 signext)
+declare !callgraph !2 i32 @bar(i8 signext)
 
 !0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
 !1 = !{!2}

>From 973ab944bf99d79d1b6a432dd87d297d8dfecb5d Mon Sep 17 00:00:00 2001
From: prabhukr <[email protected]>
Date: Wed, 17 Jun 2026 17:50:40 -0700
Subject: [PATCH 2/2] remove has existing genaralized type metadata calls

---
 clang/lib/CodeGen/CodeGenModule.cpp | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25675f99258b4..e7f058dcd4776 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3388,11 +3388,6 @@ 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);
-  return MD && MD->hasGeneralizedMDString();
-}
-
 void CodeGenModule::createIndirectFunctionTypeMD(const FunctionDecl *FD,
                                                  llvm::Function *F) {
   // All functions which are not internal linkage could be indirect targets.
@@ -3425,12 +3420,10 @@ void 
CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
                                            /*GeneralizePointers=*/false);
   llvm::Metadata *MD = CreateMetadataIdentifierForType(FnType);
   F->addTypeMetadata(0, MD);
-  // Add the generalized identifier if not added already.
-  if (!hasExistingGeneralizedTypeMD(F)) {
-    QualType GenPtrFnType = GeneralizeFunctionType(getContext(), FD->getType(),
-                                                   
/*GeneralizePointers=*/true);
-    F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(GenPtrFnType));
-  }
+
+  QualType GenPtrFnType = GeneralizeFunctionType(getContext(), FD->getType(),
+                                                 /*GeneralizePointers=*/true);
+  F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(GenPtrFnType));
 
   // Emit a hash-based bit set entry for cross-DSO calls.
   if (CodeGenOpts.SanitizeCfiCrossDso)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to