[clang] 8e50e88 - [KeyInstr][Clang] Break and Continue stmt atoms
Orlando Cazalet-Hyams via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 3 06:26:30 PDT 2025
Author: Orlando Cazalet-Hyams
Date: 2025-06-03T14:25:48+01:00
New Revision: 8e50e882a847a8fd51ee8ec22fea5df192b14c06
URL: https://github.com/llvm/llvm-project/commit/8e50e882a847a8fd51ee8ec22fea5df192b14c06
DIFF: https://github.com/llvm/llvm-project/commit/8e50e882a847a8fd51ee8ec22fea5df192b14c06.diff
LOG: [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.
Added:
Modified:
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/test/DebugInfo/KeyInstructions/for.c
clang/test/DebugInfo/KeyInstructions/switch.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 7e1c5b7da9552..4ed2c5183c47e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1118,6 +1118,7 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {
// Create the branch.
llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+ addInstToCurrentSourceAtom(BI, nullptr);
// Calculate the innermost active normal cleanup.
EHScopeStack::stable_iterator
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index d890bdcb2dd29..205a57cbab31a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1718,6 +1718,7 @@ void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) {
if (HaveInsertPoint())
EmitStopPoint(&S);
+ ApplyAtomGroup Grp(getDebugInfo());
EmitBranchThroughCleanup(BreakContinueStack.back().BreakBlock);
}
@@ -1730,6 +1731,7 @@ void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) {
if (HaveInsertPoint())
EmitStopPoint(&S);
+ ApplyAtomGroup Grp(getDebugInfo());
EmitBranchThroughCleanup(BreakContinueStack.back().ContinueBlock);
}
diff --git a/clang/test/DebugInfo/KeyInstructions/for.c b/clang/test/DebugInfo/KeyInstructions/for.c
index b42a74a639b97..89345db9fb85f 100644
--- a/clang/test/DebugInfo/KeyInstructions/for.c
+++ b/clang/test/DebugInfo/KeyInstructions/for.c
@@ -114,6 +114,32 @@ void e() {
}
+void f() {
+// - Check the `continue` keyword gets an atom group.
+// CHECK: entry:
+// CHECK-NEXT: br label %for.cond
+
+// CHECK: for.cond:
+// CHECK: br label %for.cond, !dbg [[fG1R1:!.*]], !llvm.loop
+ for ( ; ; )
+ {
+ continue;
+ }
+}
+
+void g() {
+// - Check the `break` keyword gets an atom group.
+// CHECK: entry:
+// CHECK-NEXT: br label %for.cond
+
+// CHECK: for.cond:
+// CHECK: br label %for.end, !dbg [[gG1R1:!.*]]
+ for ( ; ; )
+ {
+ break;
+ }
+}
+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
@@ -143,3 +169,7 @@ void e() {
// CHECK: [[eG3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
// CHECK: [[eG3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
// CHECK: [[eG4R1]] = !DILocation(line: 113, column: 5, scope: ![[#]], atomGroup: 4, atomRank: 1)
+
+// CHECK: [[fG1R1]] = !DILocation(line: 126, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)
+
+// CHECK: [[gG1R1]] = !DILocation(line: 139, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)
diff --git a/clang/test/DebugInfo/KeyInstructions/switch.c b/clang/test/DebugInfo/KeyInstructions/switch.c
index 5142f204ff587..96b18592621d5 100644
--- a/clang/test/DebugInfo/KeyInstructions/switch.c
+++ b/clang/test/DebugInfo/KeyInstructions/switch.c
@@ -16,18 +16,19 @@ void a(int A, int B) {
// CHECK: i32 1, label %sw.bb1
// CHECK: ], !dbg [[G2R1:!.*]]
switch ((g = A)) {
+// CHECK: br label %sw.epilog[[#]], !dbg [[G3R1:!.*]]
case 0: break;
case 1: {
// CHECK: sw.bb1:
-// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G4R2:!.*]]
// CHECK: switch i32 %1, label %{{.*}} [
// CHECK: i32 0, label %sw.bb2
-// CHECK: ], !dbg [[G3R1:!.*]]
+// CHECK: ], !dbg [[G4R1:!.*]]
switch ((B)) {
case 0: {
// Test that assignments in constant-folded switches don't go missing.
// CHECK-CXX: sw.bb2:
-// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G5R1:!.*]]
#ifdef __cplusplus
switch (const int C = 1; C) {
case 0: break;
@@ -35,17 +36,16 @@ void a(int A, int B) {
default: break;
}
#endif
- } break;
- default: break;
+ };
}
- } break;
- default: break;
+ };
}
}
// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
-// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
-// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
+// CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)
More information about the cfe-commits
mailing list