Skip to content

Commit 3b449bd

Browse files
committed
[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)
RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Reviewed By: jmmartinez Authored-by: Kristina Bessonova <[email protected]> Differential Revision: https://reviews.llvm.org/D144006
1 parent 98bd0d9 commit 3b449bd

31 files changed

+1236
-194
lines changed

clang/test/CodeGen/debug-info-codeview-unnamed.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) {
88
//
99
struct { int bar; } one = {42};
1010
//
11-
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "one"
12-
// LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
13-
// LINUX-SAME: )
14-
// LINUX: [[TYPE_OF_ONE]] = distinct !DICompositeType(
11+
// LINUX: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
1512
// LINUX-SAME: tag: DW_TAG_structure_type
1613
// LINUX-NOT: name:
1714
// LINUX-NOT: identifier:
1815
// LINUX-SAME: )
16+
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "one"
17+
// LINUX-SAME: type: [[TYPE_OF_ONE]]
18+
// LINUX-SAME: )
1919
//
20-
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "one"
21-
// MSVC-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
22-
// MSVC-SAME: )
23-
// MSVC: [[TYPE_OF_ONE]] = distinct !DICompositeType
20+
// MSVC: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
2421
// MSVC-SAME: tag: DW_TAG_structure_type
2522
// MSVC-NOT: name:
2623
// MSVC-NOT: identifier:
2724
// MSVC-SAME: )
25+
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "one"
26+
// MSVC-SAME: type: [[TYPE_OF_ONE]]
27+
// MSVC-SAME: )
2828

2929
return 0;
3030
}

clang/test/CodeGen/debug-info-unused-types.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ void quux(void) {
1818
// CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
1919
// CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "bar"
2020
// CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
21-
// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
22-
// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
23-
// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], [[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
24-
// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
25-
// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
26-
// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz"
27-
// CHECK: [[TYPE7]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "y"
21+
// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], [[TYPE4:![0-9]+]], {{![0-9]+}}}
22+
// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
23+
// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
24+
// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "baz"
25+
// CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "quux", {{.*}}, retainedNodes: [[SPRETNODES:![0-9]+]]
26+
// CHECK: [[SPRETNODES]] = !{[[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], [[TYPE8:![0-9]+]]}
27+
// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "y"
28+
// CHECK: [[TYPE6]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
29+
// CHECK: [[TYPE7:![0-9]+]] = !DIEnumerator(name: "Z"
2830
// CHECK: [[TYPE8]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "w"
2931

3032
// Check that debug info is not emitted for the typedef, struct, enum, and

clang/test/CodeGen/debug-info-unused-types.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ void quux() {
1313
// CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
1414
// CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "baz"
1515
// CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAZ"
16-
// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
17-
// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
18-
// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], {{![0-9]+}}, [[TYPE6:![0-9]+]], [[TYPE2]]}
19-
// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "foo"
20-
// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "bar"
21-
// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "y"
16+
// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], {{![0-9]+}}}
17+
// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "foo"
18+
// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "bar"
19+
// CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "quux", {{.*}}, retainedNodes: [[SPRETNODES:![0-9]+]]
20+
// CHECK: [[SPRETNODES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]]}
21+
// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "y", scope: [[SP]]
22+
// CHECK: [[TYPE5]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z", scope: [[SP]]
23+
// CHECK: [[TYPE6:![0-9]+]] = !DIEnumerator(name: "Z"
2224

2325
// NODBG-NOT: !DI{{CompositeType|Enumerator|DerivedType}}
2426

clang/test/CodeGenCXX/debug-info-access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class B : public A {
1818
static int public_static;
1919

2020
protected:
21+
// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "prot_using",{{.*}} line: [[@LINE+3]],{{.*}} flags: DIFlagProtected)
2122
// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "prot_typedef",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagProtected)
2223
typedef int prot_typedef;
23-
// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "prot_using",{{.*}} line: [[@LINE+1]],{{.*}} flags: DIFlagProtected)
2424
using prot_using = prot_typedef;
2525
prot_using prot_member;
2626

clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ void instantiate(int x) {
5151
// CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
5252
// CHECK: !DIGlobalVariable(name: "result", {{.*}} isLocal: false, isDefinition: true
5353
// CHECK: !DIGlobalVariable(name: "value", {{.*}} isLocal: false, isDefinition: true
54-
// CHECK: !DILocalVariable(name: "i", {{.*}}, flags: DIFlagArtificial
55-
// CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial
56-
// CHECK: !DILocalVariable(
57-
// CHECK-NOT: name:
58-
// CHECK: type: ![[UNION:[0-9]+]]
59-
// CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
54+
// CHECK: ![[UNION:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_union_type,
6055
// CHECK-NOT: name:
6156
// CHECK: elements
6257
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]],
6358
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]],
59+
// CHECK: !DILocalVariable(name: "i", {{.*}}, flags: DIFlagArtificial
60+
// CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial
61+
// CHECK: !DILocalVariable(
62+
// CHECK-NOT: name:
63+
// CHECK: type: ![[UNION]]

clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,72 @@
33

44
int main(int argc, char* argv[], char* arge[]) {
55
//
6+
// LINUX: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType(
7+
// LINUX-SAME: tag: DW_TAG_structure_type
8+
// LINUX-NOT: name:
9+
// LINUX-NOT: identifier:
10+
// LINUX-SAME: )
11+
//
12+
// MSVC: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType
13+
// MSVC-SAME: tag: DW_TAG_structure_type
14+
// MSVC-SAME: name: "<unnamed-type-one>"
15+
// MSVC-SAME: identifier: ".?AU<unnamed-type-one>@?1??main@@9@"
16+
// MSVC-SAME: )
17+
18+
19+
//
20+
// LINUX: [[TYPE_OF_TWO:![0-9]+]] = distinct !DICompositeType(
21+
// LINUX-SAME: tag: DW_TAG_structure_type
22+
// LINUX-NOT: name:
23+
// LINUX-NOT: identifier:
24+
// LINUX-SAME: )
25+
//
26+
// MSVC: [[TYPE_OF_TWO:![0-9]+]] = distinct !DICompositeType
27+
// MSVC-SAME: tag: DW_TAG_structure_type
28+
// MSVC-SAME: name: "<unnamed-type-two>"
29+
// MSVC-SAME: identifier: ".?AU<unnamed-type-two>@?2??main@@9@"
30+
// MSVC-SAME: )
31+
32+
33+
//
34+
// LINUX: [[TYPE_OF_THREE:![0-9]+]] = distinct !DICompositeType(
35+
// LINUX-SAME: tag: DW_TAG_structure_type
36+
// LINUX-SAME: name: "named"
37+
// LINUX-NOT: identifier:
38+
// LINUX-SAME: )
39+
//
40+
// MSVC: [[TYPE_OF_THREE:![0-9]+]] = distinct !DICompositeType
41+
// MSVC-SAME: tag: DW_TAG_structure_type
42+
// MSVC-SAME: name: "named"
43+
// MSVC-SAME: identifier: ".?AUnamed@?1??main@@9@"
44+
// MSVC-SAME: )
45+
46+
//
47+
// LINUX: [[TYPE_OF_FOUR:![0-9]+]] = distinct !DICompositeType(
48+
// LINUX-SAME: tag: DW_TAG_class_type
49+
// LINUX-NOT: name:
50+
// LINUX-NOT: identifier:
51+
// LINUX-SAME: )
52+
//
53+
// MSVC: [[TYPE_OF_FOUR:![0-9]+]] = distinct !DICompositeType
54+
// MSVC-SAME: tag: DW_TAG_class_type
55+
// MSVC-SAME: name: "<lambda_0>"
56+
// MSVC-SAME: identifier: ".?AV<lambda_0>@?0??main@@9@"
57+
// MSVC-SAME: )
58+
59+
660
// In CodeView, the LF_MFUNCTION entry for "bar()" refers to the forward
761
// reference of the unnamed struct. Visual Studio requires a unique
862
// identifier to match the LF_STRUCTURE forward reference to the definition.
963
//
1064
struct { void bar() {} } one;
1165
//
1266
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "one"
13-
// LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
14-
// LINUX-SAME: )
15-
// LINUX: [[TYPE_OF_ONE]] = distinct !DICompositeType(
16-
// LINUX-SAME: tag: DW_TAG_structure_type
17-
// LINUX-NOT: name:
18-
// LINUX-NOT: identifier:
67+
// LINUX-SAME: type: [[TYPE_OF_ONE]]
1968
// LINUX-SAME: )
2069
//
2170
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "one"
22-
// MSVC-SAME: type: [[TYPE_OF_ONE:![0-9]+]]
23-
// MSVC-SAME: )
24-
// MSVC: [[TYPE_OF_ONE]] = distinct !DICompositeType
25-
// MSVC-SAME: tag: DW_TAG_structure_type
26-
// MSVC-SAME: name: "<unnamed-type-one>"
27-
// MSVC-SAME: identifier: ".?AU<unnamed-type-one>@?1??main@@9@"
71+
// MSVC-SAME: type: [[TYPE_OF_ONE]]
2872
// MSVC-SAME: )
2973

3074

@@ -36,21 +80,11 @@ int main(int argc, char* argv[], char* arge[]) {
3680
int decltype(two)::*ptr2unnamed = &decltype(two)::bar;
3781
//
3882
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "two"
39-
// LINUX-SAME: type: [[TYPE_OF_TWO:![0-9]+]]
40-
// LINUX-SAME: )
41-
// LINUX: [[TYPE_OF_TWO]] = distinct !DICompositeType(
42-
// LINUX-SAME: tag: DW_TAG_structure_type
43-
// LINUX-NOT: name:
44-
// LINUX-NOT: identifier:
83+
// LINUX-SAME: type: [[TYPE_OF_TWO]]
4584
// LINUX-SAME: )
4685
//
4786
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "two"
48-
// MSVC-SAME: type: [[TYPE_OF_TWO:![0-9]+]]
49-
// MSVC-SAME: )
50-
// MSVC: [[TYPE_OF_TWO]] = distinct !DICompositeType
51-
// MSVC-SAME: tag: DW_TAG_structure_type
52-
// MSVC-SAME: name: "<unnamed-type-two>"
53-
// MSVC-SAME: identifier: ".?AU<unnamed-type-two>@?2??main@@9@"
87+
// MSVC-SAME: type: [[TYPE_OF_TWO]]
5488
// MSVC-SAME: )
5589

5690

@@ -61,21 +95,11 @@ int main(int argc, char* argv[], char* arge[]) {
6195
struct named { int bar; int named::* p2mem; } three = { 42, &named::bar };
6296
//
6397
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "three"
64-
// LINUX-SAME: type: [[TYPE_OF_THREE:![0-9]+]]
65-
// LINUX-SAME: )
66-
// LINUX: [[TYPE_OF_THREE]] = distinct !DICompositeType(
67-
// LINUX-SAME: tag: DW_TAG_structure_type
68-
// LINUX-SAME: name: "named"
69-
// LINUX-NOT: identifier:
98+
// LINUX-SAME: type: [[TYPE_OF_THREE]]
7099
// LINUX-SAME: )
71100
//
72101
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "three"
73-
// MSVC-SAME: type: [[TYPE_OF_THREE:![0-9]+]]
74-
// MSVC-SAME: )
75-
// MSVC: [[TYPE_OF_THREE]] = distinct !DICompositeType
76-
// MSVC-SAME: tag: DW_TAG_structure_type
77-
// MSVC-SAME: name: "named"
78-
// MSVC-SAME: identifier: ".?AUnamed@?1??main@@9@"
102+
// MSVC-SAME: type: [[TYPE_OF_THREE]]
79103
// MSVC-SAME: )
80104

81105

@@ -87,21 +111,11 @@ int main(int argc, char* argv[], char* arge[]) {
87111
auto four = [argc](int i) -> int { return argc == i ? 1 : 0; };
88112
//
89113
// LINUX: !{{[0-9]+}} = !DILocalVariable(name: "four"
90-
// LINUX-SAME: type: [[TYPE_OF_FOUR:![0-9]+]]
91-
// LINUX-SAME: )
92-
// LINUX: [[TYPE_OF_FOUR]] = distinct !DICompositeType(
93-
// LINUX-SAME: tag: DW_TAG_class_type
94-
// LINUX-NOT: name:
95-
// LINUX-NOT: identifier:
114+
// LINUX-SAME: type: [[TYPE_OF_FOUR]]
96115
// LINUX-SAME: )
97116
//
98117
// MSVC: !{{[0-9]+}} = !DILocalVariable(name: "four"
99-
// MSVC-SAME: type: [[TYPE_OF_FOUR:![0-9]+]]
100-
// MSVC-SAME: )
101-
// MSVC: [[TYPE_OF_FOUR]] = distinct !DICompositeType
102-
// MSVC-SAME: tag: DW_TAG_class_type
103-
// MSVC-SAME: name: "<lambda_0>"
104-
// MSVC-SAME: identifier: ".?AV<lambda_0>@?0??main@@9@"
118+
// MSVC-SAME: type: [[TYPE_OF_FOUR]]
105119
// MSVC-SAME: )
106120

107121
return 0;

clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ void test() {
5151
// CHECK-SAME: name: "<lambda_2_1>",
5252
c.lambda_params();
5353

54-
// CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]],
55-
// CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
54+
// CHECK: ![[LAMBDA1:[0-9]+]] = !DICompositeType(tag: DW_TAG_class_type,
5655
// CHECK-SAME: name: "<lambda_1>",
5756
// CHECK-SAME: flags: DIFlagFwdDecl
57+
// CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1]],
5858
c.lambda2();
5959
}

clang/test/CodeGenCXX/debug-lambda-this.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ int D::d(int x) {
1313
}
1414

1515
// CHECK: ![[D:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D",
16-
// CHECK: ![[POINTER:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[D]], size: 64)
1716
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "this",
1817
// CHECK-SAME: line: 11
19-
// CHECK-SAME: baseType: ![[POINTER]]
18+
// CHECK-SAME: baseType: ![[POINTER:[0-9]+]]
2019
// CHECK-SAME: size: 64
2120
// CHECK-NOT: offset: 0
2221
// CHECK-SAME: ){{$}}
22+
// CHECK: ![[POINTER]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[D]], size: 64)

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace llvm {
4949
Function *LabelFn; ///< llvm.dbg.label
5050
Function *AssignFn; ///< llvm.dbg.assign
5151

52-
SmallVector<TrackingMDNodeRef, 4> AllEnumTypes;
52+
SmallVector<TrackingMDNodeRef, 4> EnumTypes;
5353
/// Track the RetainTypes, since they can be updated later on.
5454
SmallVector<TrackingMDNodeRef, 4> AllRetainTypes;
5555
SmallVector<DISubprogram *, 4> AllSubprograms;
@@ -64,8 +64,8 @@ namespace llvm {
6464
SmallVector<TrackingMDNodeRef, 4> UnresolvedNodes;
6565
bool AllowUnresolvedNodes;
6666

67-
/// Each subprogram's preserved local variables, labels and imported
68-
/// entities.
67+
/// Each subprogram's preserved local variables, labels, imported entities,
68+
/// and types.
6969
///
7070
/// Do not use a std::vector. Some versions of libc++ apparently copy
7171
/// instead of move on grow operations, and TrackingMDRef is expensive to

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class DebugInfoFinder {
114114
void processCompileUnit(DICompileUnit *CU);
115115
void processScope(DIScope *Scope);
116116
void processType(DIType *DT);
117+
void processLocalVariable(DILocalVariable *DV);
117118
bool addCompileUnit(DICompileUnit *CU);
118119
bool addGlobalVariable(DIGlobalVariableExpression *DIG);
119120
bool addScope(DIScope *Scope);

0 commit comments

Comments
 (0)