From: Mike Stump Date: Thu, 30 Apr 2009 00:19:40 +0000 (+0000) Subject: Sema checking for incorrect placement of __block. Radar 6441502 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ea000bf621552252e41fc870346e7048646709dc;p=clang Sema checking for incorrect placement of __block. Radar 6441502 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70452 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index bf70de99eb..3a33a0678e 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1614,6 +1614,8 @@ def err_noreturn_function_has_return_expr : Error< "function %0 declared 'noreturn' should not return">; def err_noreturn_block_has_return_expr : Error< "block declared 'noreturn' should not return">; +def err_block_on_nonlocal : Error< + "__block attribute not allowed, only allowed on local variables">; def err_shufflevector_non_vector : Error< "first two arguments to __builtin_shufflevector must be vectors">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4d6a103ccd..9e2bd444f8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1909,6 +1909,11 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl, return NewVD->setInvalidDecl(); } + if (!NewVD->hasLocalStorage() && NewVD->hasAttr()) { + Diag(NewVD->getLocation(), diag::err_block_on_nonlocal); + return NewVD->setInvalidDecl(); + } + if (PrevDecl) { Redeclaration = true; MergeVarDecl(NewVD, PrevDecl); @@ -2818,6 +2823,10 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { IdResolver.AddDecl(New); ProcessDeclAttributes(New, D); + + if (New->hasAttr()) { + Diag(New->getLocation(), diag::err_block_on_nonlocal); + } return DeclPtrTy::make(New); } @@ -4256,4 +4265,3 @@ Sema::DeclPtrTy Sema::ActOnFileScopeAsmDecl(SourceLocation Loc, return DeclPtrTy::make(FileScopeAsmDecl::Create(Context, CurContext, Loc, AsmString)); } - diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c index d4b4088aee..397d3e5af6 100644 --- a/test/Sema/block-misc.c +++ b/test/Sema/block-misc.c @@ -146,3 +146,11 @@ void (^test15f)(void); void test15() { foo(^{ return LESS; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)', expected 'long (^)()'}} } + +__block int test16i; // expected-error {{__block attribute not allowed, only allowed on local variables}} + +void test16(__block int i) { // expected-error {{__block attribute not allowed, only allowed on local variables}} + extern __block double extern_var; // expected-error {{__block attribute not allowed, only allowed on local variables}} + static __block char * pch; // expected-error {{__block attribute not allowed, only allowed on local variables}} +} +