[PATCH] D109940: Fixed bug with clang where a fallthrough switch statement wasn't getting proper debug information

Shubham Sandeep Rastogi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 17 09:55:35 PDT 2021


rastogishubham updated this revision to Diff 373263.
rastogishubham added a comment.

The -v on the lit test has been removed


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109940/new/

https://reviews.llvm.org/D109940

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/switch-fallthrough.c


Index: clang/test/CodeGen/switch-fallthrough.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/switch-fallthrough.c
@@ -0,0 +1,17 @@
+// RUN:  %clang_cc1 -triple x86_64-apple-macosx11.0.0 -debug-info-kind=standalone -emit-llvm %s -o - | FileCheck %s
+// CHECK: ], !dbg !{{[0-9]+}}
+// CHECK-EMPTY:
+// CHECK-NEXT: {{.+}}
+// CHECK-NEXT: br {{.+}}, !dbg !{{[0-9+]}}
+// CHECK-EMPTY:
+// CHECK-NEXT: {{.+}}
+// CHECK-NEXT: br {{.+}}, !dbg ![[LOC:[0-9]+]]
+void test(int num) {
+  switch (num) {
+  case 0:
+    break;
+  case 10: // CHECK: ![[LOC]] = !DILocation(line: [[@LINE]], column:{{.+}}, scope: {{.+}})
+  default:
+    break;
+  }
+}
\ No newline at end of file
Index: clang/lib/CodeGen/CGStmt.cpp
===================================================================
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -1518,6 +1518,11 @@
     NextCase = dyn_cast<CaseStmt>(CurCase->getSubStmt());
   }
 
+  // Generate a stop point for debug info if the case statement is followed
+  // by a default statement.
+  if (CurCase->getSubStmt()->getStmtClass() == Stmt::DefaultStmtClass) {
+    EmitStopPoint(CurCase);
+  }
   // Normal default recursion for non-cases.
   EmitStmt(CurCase->getSubStmt());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109940.373263.patch
Type: text/x-patch
Size: 1284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210917/bc802de9/attachment.bin>


More information about the llvm-commits mailing list