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

>From f83ca146de97e956c559926b75878c2f091d77b0 Mon Sep 17 00:00:00 2001
From: prabhukr <[email protected]>
Date: Wed, 11 Mar 2026 05:23:34 +0000
Subject: [PATCH 1/3] Fix callee type generation

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

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 3b64be7a477d6..79a0eeba80348 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3267,8 +3267,10 @@ void 
CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
 
 void CodeGenModule::createCalleeTypeMetadataForIcall(const QualType &QT,
                                                      llvm::CallBase *CB) {
-  // Only if needed for call graph section and only for indirect calls.
-  if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall())
+  // Only if needed for call graph section and only for indirect calls that are
+  // visible externally.
+  if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall() ||
+      !isExternallyVisible(QT->getLinkage()))
     return;
 
   llvm::Metadata *TypeIdMD = CreateMetadataIdentifierGeneralized(QT);

>From f8ff06c8966ac678db0ed01a59140809206dd61e Mon Sep 17 00:00:00 2001
From: prabhukr <[email protected]>
Date: Thu, 12 Mar 2026 23:12:28 +0000
Subject: [PATCH 2/3] Improve test file

---
 .../CodeGen/call-graph-section-internal.cpp   | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 clang/test/CodeGen/call-graph-section-internal.cpp

diff --git a/clang/test/CodeGen/call-graph-section-internal.cpp 
b/clang/test/CodeGen/call-graph-section-internal.cpp
new file mode 100644
index 0000000000000..58eac2914324a
--- /dev/null
+++ b/clang/test/CodeGen/call-graph-section-internal.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fexperimental-call-graph-section -disable-llvm-passes 
-emit-llvm -o - %s | FileCheck %s
+
+// Check that we do not generate callee_type metadata for indirect calls
+// to functions with internal linkage (e.g., types in anonymous namespaces),
+// as their type metadata identifiers are distinct MDNodes instead of 
+// generalized strings, which would fail the LLVM Verifier.
+
+namespace {
+class a;
+class b {
+public:
+  virtual void c(a);
+};
+class a {
+public:
+  b &e;
+  void d() { e.c(*this); }
+};
+
+void f() {
+  a *g = nullptr;
+  g->d();
+}
+} // namespace
+
+void test() {
+  f();
+}
+
+// CHECK-LABEL: define {{.*}} void @{{.*}}1a1dEv
+// CHECK:   %[[VFN:.*]] = getelementptr inbounds ptr, ptr %{{.*}}, i{{[0-9]+}} 0
+// CHECK:   %[[FP:.*]] = load ptr, ptr %[[VFN]], align {{[0-9]+}}
+// CHECK:   call void %[[FP]]({{.*}})
+// CHECK-NOT: !callee_type
+// CHECK:   ret void

>From b956d58d514f5594959e649e29e4410b2cecf0be Mon Sep 17 00:00:00 2001
From: prabhukr <[email protected]>
Date: Fri, 13 Mar 2026 03:16:52 +0000
Subject: [PATCH 3/3] use a triple so we can assume mangling that's not windows
 in check lines.

---
 clang/test/CodeGen/call-graph-section-internal.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGen/call-graph-section-internal.cpp 
b/clang/test/CodeGen/call-graph-section-internal.cpp
index 58eac2914324a..1f40ec3473e83 100644
--- a/clang/test/CodeGen/call-graph-section-internal.cpp
+++ b/clang/test/CodeGen/call-graph-section-internal.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fexperimental-call-graph-section -disable-llvm-passes 
-emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux 
-fexperimental-call-graph-section -disable-llvm-passes -emit-llvm -o - %s | 
FileCheck %s
 
 // Check that we do not generate callee_type metadata for indirect calls
 // to functions with internal linkage (e.g., types in anonymous namespaces),

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

Reply via email to