Skip to content

Commit 233fdcb

Browse files
OCHyamstru
authored andcommitted
[KeyInstr] goto stmt atoms (llvm#149101)
(cherry picked from commit 5c7c855)
1 parent 54c87e7 commit 233fdcb

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,13 @@ void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) {
846846
if (HaveInsertPoint())
847847
EmitStopPoint(&S);
848848

849+
ApplyAtomGroup Grp(getDebugInfo());
849850
EmitBranchThroughCleanup(getJumpDestForLabel(S.getLabel()));
850851
}
851852

852853

853854
void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
855+
ApplyAtomGroup Grp(getDebugInfo());
854856
if (const LabelDecl *Target = S.getConstantTarget()) {
855857
EmitBranchThroughCleanup(getJumpDestForLabel(Target));
856858
return;
@@ -869,6 +871,8 @@ void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
869871
cast<llvm::PHINode>(IndGotoBB->begin())->addIncoming(V, CurBB);
870872

871873
EmitBranch(IndGotoBB);
874+
if (CurBB && CurBB->getTerminator())
875+
addInstToCurrentSourceAtom(CurBB->getTerminator(), nullptr);
872876
}
873877

874878
void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -x c++ -std=c++17 %s -debug-info-kind=line-tables-only -emit-llvm -o - -gno-column-info \
2+
// RUN: | FileCheck %s
3+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -gkey-instructions -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - -gno-column-info \
4+
// RUN: | FileCheck %s
5+
6+
// Check the goto branches get Key Instructions metadata.
7+
void ext();
8+
void test_goto(void) {
9+
// CHECK: br label %dst1, !dbg [[G1R1:!.*]]
10+
goto dst1;
11+
dst1:
12+
ext();
13+
14+
void *ptr = &&dst2;
15+
// CHECK: br label %indirectgoto, !dbg [[G3R1:!.*]]
16+
goto *ptr;
17+
dst2:
18+
ext();
19+
20+
// CHECK: br label %dst3, !dbg [[G4R1:!.*]]
21+
goto *&&dst3;
22+
dst3:
23+
ext();
24+
25+
return;
26+
}
27+
28+
// CHECK: [[G1R1]] = !DILocation(line: 10, scope: ![[#]], atomGroup: 1, atomRank: 1)
29+
// CHECK: [[G3R1]] = !DILocation(line: 16, scope: ![[#]], atomGroup: 3, atomRank: 1)
30+
// CHECK: [[G4R1]] = !DILocation(line: 21, scope: ![[#]], atomGroup: 4, atomRank: 1)

0 commit comments

Comments
 (0)