[cfe-commits] r69461 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/scope-check.c

Chris Lattner sabre at nondot.org
Sat Apr 18 12:42:37 PDT 2009


Author: lattner
Date: Sat Apr 18 14:42:37 2009
New Revision: 69461

URL: http://llvm.org/viewvc/llvm-project?rev=69461&view=rev
Log:
first step to getting switches giving "jump into vla scope" errors.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69461&r1=69460&r2=69461&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 18 14:42:37 2009
@@ -832,6 +832,8 @@
 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<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=69461&r1=69460&r2=69461&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 18 14:42:37 2009
@@ -3070,8 +3070,13 @@
       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));

Modified: cfe/trunk/test/Sema/scope-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/scope-check.c?rev=69461&r1=69460&r2=69461&view=diff

==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Sat Apr 18 14:42:37 2009
@@ -46,5 +46,16 @@
   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.





More information about the cfe-commits mailing list