Skip to content

Commit 8e50e88

Browse files
committed
[KeyInstr][Clang] Break and Continue stmt atoms
[KeyInstr][Clang] For stmt atom (#134646) This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. RFC: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.
1 parent 41a4b04 commit 8e50e88

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

clang/lib/CodeGen/CGCleanup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {
11181118

11191119
// Create the branch.
11201120
llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
1121+
addInstToCurrentSourceAtom(BI, nullptr);
11211122

11221123
// Calculate the innermost active normal cleanup.
11231124
EHScopeStack::stable_iterator

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,7 @@ void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) {
17181718
if (HaveInsertPoint())
17191719
EmitStopPoint(&S);
17201720

1721+
ApplyAtomGroup Grp(getDebugInfo());
17211722
EmitBranchThroughCleanup(BreakContinueStack.back().BreakBlock);
17221723
}
17231724

@@ -1730,6 +1731,7 @@ void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) {
17301731
if (HaveInsertPoint())
17311732
EmitStopPoint(&S);
17321733

1734+
ApplyAtomGroup Grp(getDebugInfo());
17331735
EmitBranchThroughCleanup(BreakContinueStack.back().ContinueBlock);
17341736
}
17351737

clang/test/DebugInfo/KeyInstructions/for.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,32 @@ void e() {
114114
}
115115

116116

117+
void f() {
118+
// - Check the `continue` keyword gets an atom group.
119+
// CHECK: entry:
120+
// CHECK-NEXT: br label %for.cond
121+
122+
// CHECK: for.cond:
123+
// CHECK: br label %for.cond, !dbg [[fG1R1:!.*]], !llvm.loop
124+
for ( ; ; )
125+
{
126+
continue;
127+
}
128+
}
129+
130+
void g() {
131+
// - Check the `break` keyword gets an atom group.
132+
// CHECK: entry:
133+
// CHECK-NEXT: br label %for.cond
134+
135+
// CHECK: for.cond:
136+
// CHECK: br label %for.end, !dbg [[gG1R1:!.*]]
137+
for ( ; ; )
138+
{
139+
break;
140+
}
141+
}
142+
117143
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
118144
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
119145
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
@@ -143,3 +169,7 @@ void e() {
143169
// CHECK: [[eG3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
144170
// CHECK: [[eG3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
145171
// CHECK: [[eG4R1]] = !DILocation(line: 113, column: 5, scope: ![[#]], atomGroup: 4, atomRank: 1)
172+
173+
// CHECK: [[fG1R1]] = !DILocation(line: 126, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)
174+
175+
// CHECK: [[gG1R1]] = !DILocation(line: 139, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)

clang/test/DebugInfo/KeyInstructions/switch.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ void a(int A, int B) {
1616
// CHECK: i32 1, label %sw.bb1
1717
// CHECK: ], !dbg [[G2R1:!.*]]
1818
switch ((g = A)) {
19+
// CHECK: br label %sw.epilog[[#]], !dbg [[G3R1:!.*]]
1920
case 0: break;
2021
case 1: {
2122
// CHECK: sw.bb1:
22-
// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
23+
// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G4R2:!.*]]
2324
// CHECK: switch i32 %1, label %{{.*}} [
2425
// CHECK: i32 0, label %sw.bb2
25-
// CHECK: ], !dbg [[G3R1:!.*]]
26+
// CHECK: ], !dbg [[G4R1:!.*]]
2627
switch ((B)) {
2728
case 0: {
2829
// Test that assignments in constant-folded switches don't go missing.
2930
// CHECK-CXX: sw.bb2:
30-
// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]
31+
// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G5R1:!.*]]
3132
#ifdef __cplusplus
3233
switch (const int C = 1; C) {
3334
case 0: break;
3435
case 1: break;
3536
default: break;
3637
}
3738
#endif
38-
} break;
39-
default: break;
39+
};
4040
}
41-
} break;
42-
default: break;
41+
};
4342
}
4443
}
4544

4645
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
4746
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
4847
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
49-
// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
5048
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
51-
// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
49+
// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
50+
// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
51+
// CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)

0 commit comments

Comments
 (0)