]> granicus.if.org Git - clang/commitdiff
first step to getting switches giving "jump into vla scope" errors.
authorChris Lattner <sabre@nondot.org>
Sat, 18 Apr 2009 19:42:37 +0000 (19:42 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 18 Apr 2009 19:42:37 +0000 (19:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69461 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/scope-check.c

index bf2ff2dd4551e6c8eff44c38a94c33d09d114ac3..9560614058f4dd716ce0a60c4ce10c9c98b7bc21 100644 (file)
@@ -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<
index 772db3b24783ac1ffb2eb8fb6e4403389a2f3e94..48351407d9893f85fe1bb2b60d4e50f3a1f7b65c 100644 (file)
@@ -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));
index 4c3480ea27537e6efc5c642e52ecba1fc0764c1d..59d4d134a81792af3d652f4359575cd24d66aef1 100644 (file)
@@ -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.