diff --git a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp index 34174f98b7e37..ca918f6e17b38 100644 --- a/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp +++ b/llvm/lib/DWARFLinker/Parallel/SyntheticTypeNameBuilder.cpp @@ -377,8 +377,10 @@ Error SyntheticTypeNameBuilder::addTypeName(UnitEntryPairTy InputUnitEntryPair, } break; } - // If name for the DIE is not determined yet add referenced types to the name. - if (!HasLinkageName && !HasShortName && !HasDeclFileName) { + // If name for the DIE is not determined yet or if the DIE is a typedef, add + // referenced types to the name. + if ((!HasLinkageName && !HasShortName && !HasDeclFileName) || + InputUnitEntryPair.DieEntry->getTag() == dwarf::DW_TAG_typedef) { if (InputUnitEntryPair.CU->find(InputUnitEntryPair.DieEntry, getODRAttributes())) if (Error Err = addReferencedODRDies(InputUnitEntryPair, AddParentNames, diff --git a/llvm/test/tools/dsymutil/Inputs/typedefs-with-same-name.o b/llvm/test/tools/dsymutil/Inputs/typedefs-with-same-name.o new file mode 100644 index 0000000000000..6cc47c1a783b3 Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/typedefs-with-same-name.o differ diff --git a/llvm/test/tools/dsymutil/X86/DWARFLinkerParallel/odr-fwd-declaration.test b/llvm/test/tools/dsymutil/X86/DWARFLinkerParallel/odr-fwd-declaration.test index d028194f7e83a..fd15ce3e18978 100644 --- a/llvm/test/tools/dsymutil/X86/DWARFLinkerParallel/odr-fwd-declaration.test +++ b/llvm/test/tools/dsymutil/X86/DWARFLinkerParallel/odr-fwd-declaration.test @@ -35,14 +35,14 @@ void foo() { Sptrptr ptr1 = 0; } // CHECK: DW_TAG_member // CHECK-NEXT: DW_AT_name{{.*}}"field" -// CHECK: 0x[[TYPEDEF_PTR_S]]: DW_TAG_typedef -// CHECK-NEXT: DW_AT_type{{.*}}{0x[[PTR_S]]} "S *" -// CHECK-NEXT: DW_AT_name{{.*}}"Sptr" - // CHECK: 0x[[TYPEDEF_PTR_PTR_S:[a-f0-9]*]]: DW_TAG_typedef // CHECK-NEXT: DW_AT_type{{.*}}{0x[[PTR_PTR_S]]} "Sptr *" // CHECK-NEXT: DW_AT_name{{.*}}"Sptrptr" +// CHECK: 0x[[TYPEDEF_PTR_S]]: DW_TAG_typedef +// CHECK-NEXT: DW_AT_type{{.*}}{0x[[PTR_S]]} "S *" +// CHECK-NEXT: DW_AT_name{{.*}}"Sptr" + // First we confirm that first compile unit properly references type. // // CHECK: DW_TAG_compile_unit diff --git a/llvm/test/tools/dsymutil/typedefs-with-same-name.test b/llvm/test/tools/dsymutil/typedefs-with-same-name.test new file mode 100644 index 0000000000000..2312f820b0452 --- /dev/null +++ b/llvm/test/tools/dsymutil/typedefs-with-same-name.test @@ -0,0 +1,41 @@ +#RUN: dsymutil --linker=parallel -f -oso-prepend-path=%p/Inputs/ -y %s -o %t.dwarf +#RUN: llvm-dwarfdump %t.dwarf | FileCheck %s + +# There should be two typedef DIE named "BarInt" in the resultant .dwarf file. +# The second should refer to the first, which refer to "Foo". +# CHECK: 0x[[FIRST_BARINT_ADDR:[0-9a-f]*]]: DW_TAG_typedef +# CHECK-NEXT: DW_AT_type (0x{{([[:xdigit:]]*)}} "Foo") +# CHECK-NEXT: DW_AT_name ("BarInt") +# CHECK: 0x{{([[:xdigit:]]*)}}: DW_TAG_typedef +# CHECK-NEXT: DW_AT_type (0x[[FIRST_BARINT_ADDR]] "BarInt") +# CHECK-NEXT: DW_AT_name ("BarInt") + +# Source: +# +# template struct Foo; +# typedef Foo BarInt; +# template +# struct [[clang::preferred_name(BarInt)]] Foo{}; +# int main() { +# BarInt barInt; +# return 0; +# } +# +# Compile with: +# +# $ clang++ -g -O0 -c typedefs-with-same-name.cpp -o typedefs-with-same-name.o +# +# To generate the debug map: +# +# $ clang++ typedefs-with-same-name.o -o typedefs-with-same-name +# $ dsymutil -dump-debug-map typedefs-with-same-name + +--- +triple: 'arm64-apple-darwin' +objects: + - filename: '/typedefs-with-same-name.o' + timestamp: 1762438746 + type: 102 + symbols: + - { sym: _main, objAddr: 0x0, binAddr: 0x100000360, size: 0x14 } +...