From: Chris Lattner Date: Sun, 19 Jul 2009 20:17:11 +0000 (+0000) Subject: enhance the goto checker to reject jumps across __block variable definitions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=be6d259a375bbec49659d54a302c4758058f2eef;p=clang enhance the goto checker to reject jumps across __block variable definitions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76376 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 9b9f96e5dc..7fc237bf0b 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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">; diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index ae863f2df1..853adaa336 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -83,6 +83,8 @@ static unsigned GetDiagForGotoScopeDecl(const Decl *D) { return diag::note_protected_by_vla; if (VD->hasAttr()) return diag::note_protected_by_cleanup; + if (VD->hasAttr()) + return diag::note_protected_by___block; } else if (const TypedefDecl *TD = dyn_cast(D)) { if (TD->getUnderlyingType()->isVariablyModifiedType()) return diag::note_protected_by_vla_typedef; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index bc497aa142..28ac9d1982 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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()) + if (isVM || NewVD->hasAttr() || + NewVD->hasAttr()) CurFunctionNeedsScopeChecking = true; if ((isVM && NewVD->hasLinkage()) || diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c index 294c295c5f..1f1cad44a9 100644 --- a/test/Sema/block-misc.c +++ b/test/Sema/block-misc.c @@ -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; +} + +