enhance the goto checker to reject jumps across __block variable definitions.
authorChris Lattner <sabre@nondot.org>
Sun, 19 Jul 2009 20:17:11 +0000 (20:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Jul 2009 20:17:11 +0000 (20:17 +0000)
llvm-svn: 76376

clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/block-misc.c

index 9b9f96e5dc9e05cfd14b9c3d206fe5c25da05583..7fc237bf0b1934ff8f0c45cac0793f1f6f27c40e 100644 (file)
@@ -1066,6 +1066,8 @@ def note_protected_by_cxx_try : Note<
   "jump bypasses initialization of try block">;
 def note_protected_by_cxx_catch : Note<
   "jump bypasses initialization of catch block">;
+def note_protected_by___block : Note<
+  "jump bypasses setup of __block variable">;
 
 def err_func_returning_array_function : Error<
   "function cannot return array or function type %0">;
index ae863f2df1ee1cddd11d77d90678f48d9074a661..853adaa33686475b79cdc4782bd69d17197fd2fb 100644 (file)
@@ -83,6 +83,8 @@ static unsigned GetDiagForGotoScopeDecl(const Decl *D) {
       return diag::note_protected_by_vla;
     if (VD->hasAttr<CleanupAttr>())
       return diag::note_protected_by_cleanup;
+    if (VD->hasAttr<BlocksAttr>())
+      return diag::note_protected_by___block;
   } else if (const TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
     if (TD->getUnderlyingType()->isVariablyModifiedType())
       return diag::note_protected_by_vla_typedef;
index bc497aa1421e117a91ed9f3f729f3e0eba447567..28ac9d1982a2b36f1ad2d6d22b6c739dbcb74e5a 100644 (file)
@@ -1954,7 +1954,8 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl,
     Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local);
 
   bool isVM = T->isVariablyModifiedType();
-  if (isVM || NewVD->hasAttr<CleanupAttr>())
+  if (isVM || NewVD->hasAttr<CleanupAttr>() ||
+      NewVD->hasAttr<BlocksAttr>())
     CurFunctionNeedsScopeChecking = true;
   
   if ((isVM && NewVD->hasLinkage()) ||
index 294c295c5f8c7657f2edbcd1aa9fe80a46b09b6d..1f1cad44a94d9023f76337aa1f04db2e22191bc0 100644 (file)
@@ -185,3 +185,16 @@ void test18() {
   void (^const  blockA)(void) = ^{ };
   blockA = ^{ }; // expected-error {{read-only variable is not assignable}}
 }
+
+// rdar://7072507
+int test19() {
+  goto L0;       // expected-error {{illegal goto into protected scope}}
+  
+  __block int x; // expected-note {{jump bypasses setup of __block variable}}
+L0:
+  x = 0;
+  ^(){ ++x; }();
+  return x;
+}
+
+