[cfe-commits] r70452 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/block-misc.c
Mike Stump
mrs at apple.com
Wed Apr 29 17:20:09 PDT 2009
Author: mrs
Date: Wed Apr 29 19:19:40 2009
New Revision: 70452
URL: http://llvm.org/viewvc/llvm-project?rev=70452&view=rev
Log:
Sema checking for incorrect placement of __block. Radar 6441502
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/block-misc.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70452&r1=70451&r2=70452&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 29 19:19:40 2009
@@ -1614,6 +1614,8 @@
"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">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=70452&r1=70451&r2=70452&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr 29 19:19:40 2009
@@ -1909,6 +1909,11 @@
return NewVD->setInvalidDecl();
}
+ if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) {
+ Diag(NewVD->getLocation(), diag::err_block_on_nonlocal);
+ return NewVD->setInvalidDecl();
+ }
+
if (PrevDecl) {
Redeclaration = true;
MergeVarDecl(NewVD, PrevDecl);
@@ -2818,6 +2823,10 @@
IdResolver.AddDecl(New);
ProcessDeclAttributes(New, D);
+
+ if (New->hasAttr<BlocksAttr>()) {
+ Diag(New->getLocation(), diag::err_block_on_nonlocal);
+ }
return DeclPtrTy::make(New);
}
@@ -4256,4 +4265,3 @@
return DeclPtrTy::make(FileScopeAsmDecl::Create(Context, CurContext,
Loc, AsmString));
}
-
Modified: cfe/trunk/test/Sema/block-misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-misc.c?rev=70452&r1=70451&r2=70452&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-misc.c (original)
+++ cfe/trunk/test/Sema/block-misc.c Wed Apr 29 19:19:40 2009
@@ -146,3 +146,11 @@
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}}
+}
+
More information about the cfe-commits
mailing list