Commit 843390c5 authored by Adrian Prantl's avatar Adrian Prantl
Browse files

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
parent 9ff848c5
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1521,6 +1521,12 @@ void CodeGenFunction::EmitCaseStmt(const CaseStmt &S,
    NextCase = dyn_cast<CaseStmt>(CurCase->getSubStmt());
  }

  // Generate a stop point for debug info if the case statement is
  // followed by a default statement. A fallthrough case before a
  // default case gets its own branch target.
  if (CurCase->getSubStmt()->getStmtClass() == Stmt::DefaultStmtClass)
    EmitStopPoint(CurCase);

  // Normal default recursion for non-cases.
  EmitStmt(CurCase->getSubStmt());
}
+17 −0
Original line number Diff line number Diff line
// 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;
  }
}