aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaDecl.cpp9
-rw-r--r--test/Sema/scope-check.c11
3 files changed, 20 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index bf2ff2dd45..9560614058 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -832,6 +832,8 @@ def err_redefinition_of_label : Error<"redefinition of label '%0'">;
def err_undeclared_label_use : Error<"use of undeclared label '%0'">;
def err_goto_into_protected_scope : Error<"illegal goto into protected scope">;
+def err_switch_into_protected_scope : Error<
+ "illegal switch into protected scope">;
def note_protected_by_vla_typedef : Note<
"jump bypasses initialization of VLA typedef">;
def note_protected_by_vla : Note<
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 772db3b247..48351407d9 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3070,8 +3070,13 @@ void JumpScopeChecker::VerifyJumps() {
assert(LabelAndGotoScopes.count(GS->getLabel()) && "Label not visited?");
CheckJump(GS, LabelAndGotoScopes[GS->getLabel()],
diag::err_goto_into_protected_scope);
- } else if (isa<SwitchStmt>(Jump)) {
- // FIXME: Handle this.
+ } else if (SwitchStmt *SS = dyn_cast<SwitchStmt>(Jump)) {
+ for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
+ SC = SC->getNextSwitchCase()) {
+ assert(LabelAndGotoScopes.count(SC) && "Case not visited?");
+ CheckJump(SS, LabelAndGotoScopes[SC],
+ diag::err_switch_into_protected_scope);
+ }
continue;
} else {
assert(isa<IndirectGotoStmt>(Jump));
diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c
index 4c3480ea27..59d4d134a8 100644
--- a/test/Sema/scope-check.c
+++ b/test/Sema/scope-check.c
@@ -46,5 +46,16 @@ int test6() {
goto x; // expected-error {{use of undeclared label 'x'}}
}
+void test7(int x) {
+foo:
+ switch (x) { // expected-error {{illegal switch into protected scope}}
+ case 1: ;
+ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
+ case 2:
+ a[1] = 2;
+ break;
+ }
+}
+
// FIXME: Switch cases etc.