[cfe-commits] r69498 - 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 18:05:26 PDT 2009


Author: lattner
Date: Sat Apr 18 20:05:26 2009
New Revision: 69498

URL: http://llvm.org/viewvc/llvm-project?rev=69498&view=rev
Log:
First half of jump scope checking for indirect goto.

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=69498&r1=69497&r2=69498&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 18 20:05:26 2009
@@ -834,6 +834,8 @@
 def err_goto_into_protected_scope : Error<"illegal goto into protected scope">;
 def err_switch_into_protected_scope : Error<
   "illegal switch case into protected scope">;
+def err_indirect_goto_in_protected_scope : Error<
+  "illegal indirect goto in protected scope, unknown effect on scopes">;
 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=69498&r1=69497&r2=69498&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 18 20:05:26 2009
@@ -3001,7 +3001,8 @@
     if (SubStmt == 0) continue;
     
     // FIXME: diagnose jumps past initialization: required in C++, warning in C.
-    //     { int X = 4;   L: } goto L;
+    //   goto L; int X = 4;   L: ;
+    // FIXME: what about jumps into C++ catch blocks, what are the rules?
 
     // If this is a declstmt with a VLA definition, it defines a scope from here
     // to the end of the containing context.
@@ -3054,7 +3055,6 @@
       
       continue;
     }
-    // FIXME: what about jumps into C++ catch blocks, what are the rules?
     
     // Recursively walk the AST.
     BuildScopeInformation(SubStmt, ParentScope);
@@ -3068,7 +3068,10 @@
     if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
       CheckJump(GS, GS->getLabel(), GS->getGotoLoc(),
                 diag::err_goto_into_protected_scope);
-    } else if (SwitchStmt *SS = dyn_cast<SwitchStmt>(Jump)) {
+      continue;
+    }
+    
+    if (SwitchStmt *SS = dyn_cast<SwitchStmt>(Jump)) {
       for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
            SC = SC->getNextSwitchCase()) {
         assert(LabelAndGotoScopes.count(SC) && "Case not visited?");
@@ -3076,11 +3079,22 @@
                   diag::err_switch_into_protected_scope);
       }
       continue;
-    } else {
-      assert(isa<IndirectGotoStmt>(Jump));
-      // FIXME: Emit an error on indirect gotos when not in scope 0.
-      continue;
     }
+    
+    
+    // We don't know where an indirect goto goes, require that it be at the
+    // top level of scoping.
+    assert(isa<IndirectGotoStmt>(Jump));
+    assert(LabelAndGotoScopes.count(Jump) &&"Jump didn't get added to scopes?");
+    unsigned GotoScope = LabelAndGotoScopes[Jump];
+    if (GotoScope == 0) continue;
+    S.Diag(Jump->getLocStart(), diag::err_indirect_goto_in_protected_scope);
+    
+    while (GotoScope != 0) {
+      S.Diag(Scopes[GotoScope].Loc, Scopes[GotoScope].Diag);
+      GotoScope = Scopes[GotoScope].ParentScope;
+    }
+    continue;
   }
 }
 

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

==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Sat Apr 18 20:05:26 2009
@@ -83,6 +83,7 @@
                        goto L6;
                    4; }); 
   L6:; // ok.
+    if (x) goto L6; // ok
   }
   
   {
@@ -113,6 +114,13 @@
     //int A[({   L11: 4; })];
   }
   
+  {
+    goto L12;
+    
+    int y = 4;   // fixme-warn: skips initializer.
+  L12:
+    ;
+  }
   
   // Statement expressions 2.
   goto L1;     // expected-error {{illegal goto into protected scope}}
@@ -121,3 +129,21 @@
                L1:
                  42; });
 }
+
+void test9(int n, void *P) {
+  int Y;
+  int Z = 4;
+  goto *P;  // ok.
+
+L2: ;
+  int a[n];  // expected-note {{jump bypasses initialization of variable length array}}
+
+L3:
+  goto *P;  // expected-error {{illegal indirect goto in protected scope, unknown effect on scopes}}
+  
+  void *Ptrs[] = {
+    &&L2,
+    &&L3   // FIXME: Not Ok.
+  };
+}
+





More information about the cfe-commits mailing list