diff options
author | Reid Kleckner <rnk@google.com> | 2018-12-11 23:07:39 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-12-11 23:07:39 +0000 |
commit | 9571c806c52caba508842c414d3a3ac3f8fd1338 (patch) | |
tree | 4abffb99c4524c61ebc5951df83bad806e99653e /llvm | |
parent | c67768fe2365e4759c54a26a9e8af987ee0bd09b (diff) | |
download | bcm5719-llvm-9571c806c52caba508842c414d3a3ac3f8fd1338.tar.gz bcm5719-llvm-9571c806c52caba508842c414d3a3ac3f8fd1338.zip |
[codeview] Look through typedefs in getCompleteTypeIndex
Summary:
Any time a symbol record, whether it's S_UDT, S_LOCAL, or S_[GL]DATA32,
references a record type, it should use the complete type index, even if
there's a typedef in the way.
Fixes the compiler part of PR39853.
Reviewers: zturner, aganea
Subscribers: hiraditya, arphaman, llvm-commits
Differential Revision: https://reviews.llvm.org/D55236
llvm-svn: 348902
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 8 | ||||
-rw-r--r-- | llvm/test/DebugInfo/COFF/udts-complete.ll | 72 |
2 files changed, 80 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 0ef90bc52e5..03d8777217a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -2486,6 +2486,14 @@ TypeIndex CodeViewDebug::getCompleteTypeIndex(DITypeRef TypeRef) { if (!Ty) return TypeIndex::Void(); + // Look through typedefs when getting the complete type index. Call + // getTypeIndex on the typdef to ensure that any UDTs are accumulated and are + // emitted only once. + if (Ty->getTag() == dwarf::DW_TAG_typedef) + (void)getTypeIndex(Ty); + while (Ty->getTag() == dwarf::DW_TAG_typedef) + Ty = cast<DIDerivedType>(Ty)->getBaseType().resolve(); + // If this is a non-record type, the complete type index is the same as the // normal type index. Just call getTypeIndex. switch (Ty->getTag()) { diff --git a/llvm/test/DebugInfo/COFF/udts-complete.ll b/llvm/test/DebugInfo/COFF/udts-complete.ll new file mode 100644 index 00000000000..1683ceabd50 --- /dev/null +++ b/llvm/test/DebugInfo/COFF/udts-complete.ll @@ -0,0 +1,72 @@ +; RUN: llc -filetype=obj %s -o %t.obj +; RUN: llvm-pdbutil dump -symbols -types %t.obj | FileCheck %s + +; Make sure that `gv`, `Bar`, and `Baz` all point to the complete type index of +; Foo (0x1002), and not the forward declaration index (0x1000). + +; C++ source: +; struct Foo { +; int x; +; }; +; typedef Foo Bar; +; typedef Bar Baz; +; static_assert(sizeof(Foo) == 4, ""); +; Baz gv; + +; CHECK: Types (.debug$T) +; CHECK-NEXT: ============================================================ +; CHECK: 0x1000 | LF_STRUCTURE [size = 36] `Foo` +; CHECK: unique name: `.?AUFoo@@` +; CHECK: vtable: <no type>, base list: <no type>, field list: <no type> +; CHECK: options: forward ref | has unique name, sizeof 0 +; CHECK: 0x1001 | LF_FIELDLIST [size = 16] +; CHECK: - LF_MEMBER [name = `x`, Type = 0x0074 (int), offset = 0, attrs = public] +; CHECK: 0x1002 | LF_STRUCTURE [size = 36] `Foo` +; CHECK: unique name: `.?AUFoo@@` +; CHECK: vtable: <no type>, base list: <no type>, field list: 0x1001 +; CHECK: options: has unique name, sizeof 4 +; CHECK: 0x1004 | LF_UDT_SRC_LINE [size = 16] +; CHECK: udt = 0x1002, file = 4099, line = 1 + +; CHECK: Symbols +; CHECK: ============================================================ +; CHECK: Mod 0000 | `.debug$S`: +; CHECK: 0 | S_GDATA32 [size = 17] `gv` +; CHECK: type = 0x1002 (Foo), addr = 0000:0000 +; CHECK: 0 | S_UDT [size = 12] `Bar` +; CHECK: original type = 0x1002 +; CHECK: 0 | S_UDT [size = 12] `Baz` +; CHECK: original type = 0x1002 +; CHECK: 0 | S_UDT [size = 12] `Foo` +; CHECK: original type = 0x1002 + +; ModuleID = 't.cpp' +source_filename = "t.cpp" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.14.26433" + +%struct.Foo = type { i32 } + +@"?gv@@3UFoo@@A" = dso_local global %struct.Foo zeroinitializer, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!12, !13, !14, !15} +!llvm.ident = !{!16} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "gv", linkageName: "?gv@@3UFoo@@A", scope: !2, file: !3, line: 7, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 8.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None) +!3 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "e21cd263d43db2ff55050be3e41e789f") +!4 = !{} +!5 = !{!0} +!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "Baz", file: !3, line: 5, baseType: !7) +!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", file: !3, line: 4, baseType: !8) +!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !3, line: 1, size: 32, flags: DIFlagTypePassByValue | DIFlagTrivial, elements: !9, identifier: ".?AUFoo@@") +!9 = !{!10} +!10 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !8, file: !3, line: 2, baseType: !11, size: 32) +!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!12 = !{i32 2, !"CodeView", i32 1} +!13 = !{i32 2, !"Debug Info Version", i32 3} +!14 = !{i32 1, !"wchar_size", i32 2} +!15 = !{i32 7, !"PIC Level", i32 2} +!16 = !{!"clang version 8.0.0 "} |