Skip to content

Commit 843390c

Browse files
committed
Apply proper source location to fallthrough switch cases.
This fixes a bug in clang where, when clang sees a switch with a fallthrough to a default like this: static void funcA(void) {} static void funcB(void) {} int main(int argc, char **argv) { switch (argc) { case 0: funcA(); break; case 10: default: funcB(); break; } } It does not add a proper debug location for that switch case, such as case 10: above. Patch by Shubham Rastogi! Differential Revision: https://reviews.llvm.org/D109940
1 parent 9ff848c commit 843390c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,12 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S,
15211521
NextCase = dyn_cast<CaseStmt>(CurCase->getSubStmt());
15221522
}
15231523

1524+
// Generate a stop point for debug info if the case statement is
1525+
// followed by a default statement. A fallthrough case before a
1526+
// default case gets its own branch target.
1527+
if (CurCase->getSubStmt()->getStmtClass() == Stmt::DefaultStmtClass)
1528+
EmitStopPoint(CurCase);
1529+
15241530
// Normal default recursion for non-cases.
15251531
EmitStmt(CurCase->getSubStmt());
15261532
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-macosx11.0.0 -debug-info-kind=standalone -emit-llvm %s -o - | FileCheck %s
2+
// CHECK: ], !dbg !{{[0-9]+}}
3+
// CHECK-EMPTY:
4+
// CHECK-NEXT: {{.+}}
5+
// CHECK-NEXT: br {{.+}}, !dbg !{{[0-9+]}}
6+
// CHECK-EMPTY:
7+
// CHECK-NEXT: {{.+}}
8+
// CHECK-NEXT: br {{.+}}, !dbg ![[LOC:[0-9]+]]
9+
void test(int num) {
10+
switch (num) {
11+
case 0:
12+
break;
13+
case 10: // CHECK: ![[LOC]] = !DILocation(line: [[@LINE]], column:{{.+}}, scope: {{.+}})
14+
default:
15+
break;
16+
}
17+
}

0 commit comments

Comments
 (0)