llvm.org GIT mirror llvm / 1f72a03
Fix bug in getCompleteTypeIndex in codeview debug info Summary: When there are multiple instances of a forward decl record type, only the first one is emitted with a type index, because the type is added to a map with a null type index. Avoid this by reordering so that forward decl types aren't added to the map. Reviewers: rnk Subscribers: aprantl, hiraditya, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61460 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360101 91177308-0d34-0410-b5e6-96231b3b80d8 Amy Huang 1 year, 5 months ago
2 changed file(s) with 80 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
24962496 return getTypeIndex(Ty);
24972497 }
24982498
2499 // Check if we've already translated the complete record type.
25002499 const auto *CTy = cast(Ty);
2501 auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()});
2502 if (!InsertResult.second)
2503 return InsertResult.first->second;
25042500
25052501 TypeLoweringScope S(*this);
25062502
25172513 if (CTy->isForwardDecl())
25182514 return FwdDeclTI;
25192515 }
2516
2517 // Check if we've already translated the complete record type.
2518 // Insert the type with a null TypeIndex to signify that the type is currently
2519 // being lowered.
2520 auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()});
2521 if (!InsertResult.second)
2522 return InsertResult.first->second;
25202523
25212524 TypeIndex TI;
25222525 switch (CTy->getTag()) {
11 ; FIXME: Add test for llc with optimizations once it is implemented.
22
33 ; Source to regenerate:
4 ; $ clang --target=x86_64-windows-msvc -S heapallocsite.c -g -gcodeview -o t.ll \
4 ; $ clang --target=x86_64-windows-msvc -S heapallocsite.cpp -g -gcodeview -o t.ll \
55 ; -emit-llvm -O0 -Xclang -disable-llvm-passes -fms-extensions
6 ; __declspec(allocator) char *myalloc(void);
7 ; void f() {
8 ; myalloc()
9 ; }
106 ;
117 ; struct Foo {
128 ; __declspec(allocator) virtual void *alloc();
139 ; };
14 ; void use_alloc(void*);
15 ; void do_alloc(Foo *p) {
10 ;
11 ; extern "C" __declspec(allocator) Foo *alloc_foo();
12 ;
13 ; extern "C" void use_alloc(void*);
14 ; extern "C" void call_virtual(Foo *p) {
1615 ; use_alloc(p->alloc());
16 ; }
17 ;
18 ; extern "C" void call_multiple() {
19 ; use_alloc(alloc_foo());
20 ; use_alloc(alloc_foo());
1721 ; }
1822
1923 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
2226 %struct.Foo = type { i32 (...)** }
2327
2428 ; Function Attrs: noinline optnone uwtable
25 define dso_local void @f() #0 !dbg !8 {
29 define dso_local void @call_virtual(%struct.Foo* %p) #0 !dbg !8 {
2630 entry:
27 %call = call i8* @myalloc(), !dbg !11, !heapallocsite !2
28 ret void, !dbg !12
31 %p.addr = alloca %struct.Foo*, align 8
32 store %struct.Foo* %p, %struct.Foo** %p.addr, align 8
33 call void @llvm.dbg.declare(metadata %struct.Foo** %p.addr, metadata !13, metadata !DIExpression()), !dbg !14
34 %0 = load %struct.Foo*, %struct.Foo** %p.addr, align 8, !dbg !15
35 %1 = bitcast %struct.Foo* %0 to i8* (%struct.Foo*)***, !dbg !15
36 %vtable = load i8* (%struct.Foo*)**, i8* (%struct.Foo*)*** %1, align 8, !dbg !15
37 %vfn = getelementptr inbounds i8* (%struct.Foo*)*, i8* (%struct.Foo*)** %vtable, i64 0, !dbg !15
38 %2 = load i8* (%struct.Foo*)*, i8* (%struct.Foo*)** %vfn, align 8, !dbg !15
39 %call = call i8* %2(%struct.Foo* %0), !dbg !15, !heapallocsite !2
40 call void @use_alloc(i8* %call), !dbg !15
41 ret void, !dbg !16
2942 }
3043
31 ; CHECK-LABEL: f: # @f
44 ; Function Attrs: nounwind readnone speculatable
45 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46
47 declare dso_local void @use_alloc(i8*) #2
48
49 ; Function Attrs: noinline optnone uwtable
50 define dso_local void @call_multiple() #0 !dbg !17 {
51 entry:
52 %call = call %struct.Foo* @alloc_foo(), !dbg !20, !heapallocsite !12
53 %0 = bitcast %struct.Foo* %call to i8*, !dbg !20
54 call void @use_alloc(i8* %0), !dbg !20
55 %call1 = call %struct.Foo* @alloc_foo(), !dbg !21, !heapallocsite !12
56 %1 = bitcast %struct.Foo* %call1 to i8*, !dbg !21
57 call void @use_alloc(i8* %1), !dbg !21
58 ret void, !dbg !22
59 }
60
61 declare dso_local %struct.Foo* @alloc_foo() #2
62
63 ; CHECK-LABEL: call_virtual: # @call_virtual
3264 ; CHECK: .Lheapallocsite0:
33 ; CHECK: callq myalloc
65 ; CHECK: callq *(%rax)
3466 ; CHECK: .Lheapallocsite1:
3567 ; CHECK: retq
3668
37 declare dso_local i8* @myalloc() #1
38
39 ; Function Attrs: noinline optnone uwtable
40 define dso_local void @do_alloc(%struct.Foo* %p) #0 !dbg !13 {
41 entry:
42 %p.addr = alloca %struct.Foo*, align 8
43 store %struct.Foo* %p, %struct.Foo** %p.addr, align 8
44 call void @llvm.dbg.declare(metadata %struct.Foo** %p.addr, metadata !18, metadata !DIExpression()), !dbg !19
45 %0 = load %struct.Foo*, %struct.Foo** %p.addr, align 8, !dbg !20
46 %1 = bitcast %struct.Foo* %0 to i8* (%struct.Foo*)***, !dbg !20
47 %vtable = load i8* (%struct.Foo*)**, i8* (%struct.Foo*)*** %1, align 8, !dbg !20
48 %vfn = getelementptr inbounds i8* (%struct.Foo*)*, i8* (%struct.Foo*)** %vtable, i64 0, !dbg !20
49 %2 = load i8* (%struct.Foo*)*, i8* (%struct.Foo*)** %vfn, align 8, !dbg !20
50 %call = call i8* %2(%struct.Foo* %0), !dbg !20, !heapallocsite !2
51 call void @use_alloc(i8* %call), !dbg !20
52 ret void, !dbg !21
53 }
54
55 ; CHECK-LABEL: do_alloc: # @do_alloc
69 ; CHECK-LABEL: call_multiple: # @call_multiple
70 ; CHECK: .Lheapallocsite4:
71 ; CHECK: callq alloc_foo
72 ; CHECK: .Lheapallocsite5:
5673 ; CHECK: .Lheapallocsite2:
57 ; CHECK: callq *(%rax)
74 ; CHECK: callq alloc_foo
5875 ; CHECK: .Lheapallocsite3:
5976 ; CHECK: retq
6077
7289 ; CHECK-NEXT: .secrel32 .Lheapallocsite2
7390 ; CHECK-NEXT: .secidx .Lheapallocsite2
7491 ; CHECK-NEXT: .short .Lheapallocsite3-.Lheapallocsite2
75 ; CHECK-NEXT: .long 3
92 ; CHECK-NEXT: .long 4096
93 ; CHECK-NEXT: .p2align 2
94
95 ; CHECK: .short 4446 # Record kind: S_HEAPALLOCSITE
96 ; CHECK-NEXT: .secrel32 .Lheapallocsite4
97 ; CHECK-NEXT: .secidx .Lheapallocsite4
98 ; CHECK-NEXT: .short .Lheapallocsite5-.Lheapallocsite4
99 ; CHECK-NEXT: .long 4096
76100 ; CHECK-NEXT: .p2align 2
77101 ; CHECK-LABEL: .short 4431 # Record kind: S_PROC_ID_END
78
79 ; Function Attrs: nounwind readnone speculatable
80 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
81
82 declare dso_local void @use_alloc(i8*) #1
83102
84103 !llvm.dbg.cu = !{!0}
85104 !llvm.module.flags = !{!3, !4, !5, !6}
86105 !llvm.ident = !{!7}
87106
88 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
89 !1 = !DIFile(filename: "heapallocsite.cpp", directory: "C:\5Csrc\5Ctest", checksumkind: CSK_MD5, checksum: "6d758cfa3834154a04ce8a55102772a9")
107 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git 9c8073f44f786fbf47335e53f20abe64429e8e47)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)!1 = !DIFile(filename: "filename", directory: "directory", checksumkind: CSK_MD5, checksum: "096443b661a0af36da9006330c08f97e")
90108 !2 = !{}
91109 !3 = !{i32 2, !"CodeView", i32 1}
92110 !4 = !{i32 2, !"Debug Info Version", i32 3}
93111 !5 = !{i32 1, !"wchar_size", i32 2}
94112 !6 = !{i32 7, !"PIC Level", i32 2}
95 !7 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 4eff3de99423a62fd6e833e29c71c1e62ba6140b)"}
96 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, scopeLine: 3, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
113 !7 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git 9c8073f44f786fbf47335e53f20abe64429e8e47)"}
114 !8 = distinct !DISubprogram(name: "call_virtual", scope: !1, file: !1, line: 8, type: !9, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
97115 !9 = !DISubroutineType(types: !10)
98 !10 = !{null}
99 !11 = !DILocation(line: 4, scope: !8)
100 !12 = !DILocation(line: 5, scope: !8)
101 !13 = distinct !DISubprogram(name: "do_alloc", scope: !1, file: !1, line: 11, type: !14, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
102 !14 = !DISubroutineType(types: !15)
103 !15 = !{null, !16}
104 !16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64)
105 !17 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 7, flags: DIFlagFwdDecl)
106 !18 = !DILocalVariable(name: "p", arg: 1, scope: !13, file: !1, line: 11, type: !16)
107 !19 = !DILocation(line: 11, scope: !13)
108 !20 = !DILocation(line: 12, scope: !13)
109 !21 = !DILocation(line: 13, scope: !13)
110
116 !10 = !{null, !11}
117 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
118 !12 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !1, line: 1, flags: DIFlagFwdDecl, identifier: ".?AUFoo@@")
119 !13 = !DILocalVariable(name: "p", arg: 1, scope: !8, file: !1, line: 8, type: !11)
120 !14 = !DILocation(line: 8, scope: !8)
121 !15 = !DILocation(line: 9, scope: !8)
122 !16 = !DILocation(line: 10, scope: !8)
123 !17 = distinct !DISubprogram(name: "call_multiple", scope: !1, file: !1, line: 12, type: !18, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
124 !18 = !DISubroutineType(types: !19)
125 !19 = !{null}
126 !20 = !DILocation(line: 13, scope: !17)
127 !21 = !DILocation(line: 14, scope: !17)
128 !22 = !DILocation(line: 15, scope: !17)