]> granicus.if.org Git - clang/commitdiff
In Microsoft mode, warn if an indirect goto jump over a variable initialization.
authorFrancois Pichet <pichet2000@gmail.com>
Fri, 16 Sep 2011 23:15:32 +0000 (23:15 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Fri, 16 Sep 2011 23:15:32 +0000 (23:15 +0000)
Also add a test case for the non Microsoft case because such test didn't exist.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139971 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/JumpDiagnostics.cpp
test/SemaCXX/MicrosoftExtensions.cpp
test/SemaCXX/scope-check.cpp

index 565a610b8c2d49a03d510a589d070fb49c91a76a..fcc3154ebecf2a0baa24c3d956ced4c7621b6e7d 100644 (file)
@@ -485,7 +485,8 @@ void JumpScopeChecker::VerifyJumps() {
     if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
       LabelDecl *Target = IGS->getConstantTarget();
       CheckJump(IGS, Target->getStmt(), IGS->getGotoLoc(),
-                diag::err_goto_into_protected_scope, 0);
+                diag::err_goto_into_protected_scope,
+                diag::warn_goto_into_protected_scope);
       continue;
     }
 
@@ -693,7 +694,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
   SmallVector<unsigned, 10> ToScopesError;
   SmallVector<unsigned, 10> ToScopesWarning;
   for (unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
-    if (S.getLangOptions().Microsoft &&
+    if (S.getLangOptions().Microsoft && JumpDiagWarning != 0 &&
         IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag))
       ToScopesWarning.push_back(I);
     else if (Scopes[I].InDiag)
index d92eda711cb4f7bf391f38442a84359a842d2bc3..396ee13f66a9e6cd1b4e9837094f6a47720e40ef 100644 (file)
@@ -258,14 +258,6 @@ void f()
 }
 
 
-
-
-
-
-
-
-
-
 namespace ms_protected_scope {
   struct C { C(); };
 
@@ -305,6 +297,14 @@ void exception_jump() {
   } catch(int) {
   }
 }
+
+int jump_over_indirect_goto() {
+  static void *ps[] = { &&a0 };
+  goto *&&a0; // expected-warning {{goto into protected scope}}
+  int a = 3; // expected-note {{jump bypasses variable initialization}}
+ a0:
+  return 0;
+}
   
 }
 
index d656a074db3f1770675e095a1114b198012e94fa..ec2f2e565fc76eb96d942731e1ccd8919e01fcfd 100644 (file)
@@ -191,4 +191,19 @@ bool recurse() {
       break;
   }
 }
+
+
+namespace test10 {
+\r
+int test() {\r
+  static void *ps[] = { &&a0 };\r
+  goto *&&a0; // expected-error {{goto into protected scope}}\r
+  int a = 3; // expected-note {{jump bypasses variable initialization}}\r
+ a0:\r
+  return 0;\r
+}
+
 }
+
+}
+