https://github.com/rastogishubham created 
https://github.com/llvm/llvm-project/pull/159592

If we use LTO as a driver, we can see that even if we have lambdas in
template parameters, two debug entries from different CUs will get
merged in LTO, but their human-readable DW_AT_name will be different if
we emit the locations in anonymous tag names.

Therefore we would never have two dies with the same linkage name but
different human readable names. Which probably should not happen.

This change prevents that from happening.

In our example:

We can see with `AnonymousTagLocations` set to true, the dwarfdump output will 
be

`DW_AT_name     ("Foo<(lambda at a.cpp:12:5){}>")`

But with `AnonymousTagLocations` set to true, the dwarfdump output will be

`DW_AT_name     ("Foo<(lambda){}>")`


>From 378959f8baa0bee9f6aa2cea5bbe3fe952ffd670 Mon Sep 17 00:00:00 2001
From: Shubham Sandeep Rastogi <srastog...@apple.com>
Date: Thu, 18 Sep 2025 07:49:37 -0700
Subject: [PATCH] Do not print locations in anonymous tag names.

If we use LTO as a driver, we can see that even if we have lambdas in
template parameters, two debug entries from different CUs will get
merged in LTO, but their human-readable DW_AT_name will be different if
we emit the locations in anonymous tag names.

Therefore we would never have two dies with the same linkage name but
different human readable names. Which probably should not happen.

This change prevents that from happening.
---
 clang/lib/CodeGen/CGDebugInfo.cpp           |  2 ++
 clang/test/DebugInfo/CXX/anonymous-locs.cpp | 14 ++++++++++++++
 2 files changed, 16 insertions(+)
 create mode 100644 clang/test/DebugInfo/CXX/anonymous-locs.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 578d09f7971d6..9df792be1f283 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -397,6 +397,8 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
 
   // Apply -fdebug-prefix-map.
   PP.Callbacks = &PrintCB;
+  // Disable printing of location of an anonymous tag name.
+  PP.AnonymousTagLocations = false;
   return PP;
 }
 
diff --git a/clang/test/DebugInfo/CXX/anonymous-locs.cpp 
b/clang/test/DebugInfo/CXX/anonymous-locs.cpp
new file mode 100644
index 0000000000000..48a8aff57d520
--- /dev/null
+++ b/clang/test/DebugInfo/CXX/anonymous-locs.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -emit-obj -debug-info-kind=standalone 
-dwarf-version=5 -triple x86_64-apple-darwin -o %t %s 
+// RUN: llvm-dwarfdump %t | FileCheck %s
+
+// CHECK: DW_TAG_structure_type
+// CHECK-NEXT: DW_AT_calling_convention        (DW_CC_pass_by_value)
+// CHECK-NEXT: DW_AT_name      ("Foo<(lambda){}>")
+
+template<auto T>
+struct Foo {
+};
+
+Foo<[] {}> f;
+
+auto func() { return f; }
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to