[cfe-commits] r56652 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Basic/DiagnosticKinds.def lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/Sema/block-literal.c
Steve Naroff
snaroff at apple.com
Fri Sep 26 07:41:30 PDT 2008
Author: snaroff
Date: Fri Sep 26 09:41:28 2008
New Revision: 56652
URL: http://llvm.org/viewvc/llvm-project?rev=56652&view=rev
Log:
Tweak Expr::isModifiableLvalue() and Expr::isLvalue() to better deal with BlockDeclRef exprs.
This fixes <rdar://problem/6248392> clang: Error when using address of stack variable inside block.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/block-literal.c
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=56652&r1=56651&r2=56652&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Sep 26 09:41:28 2008
@@ -87,7 +87,8 @@
MLV_InvalidExpression,
MLV_IncompleteType,
MLV_ConstQualified,
- MLV_ArrayType
+ MLV_ArrayType,
+ MLV_NotBlockQualified
};
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=56652&r1=56651&r2=56652&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Sep 26 09:41:28 2008
@@ -1036,6 +1036,8 @@
DIAG(err_typecheck_duplicate_vector_components_not_mlvalue, ERROR,
"vector is not assignable (contains duplicate components)")
+DIAG(err_block_decl_ref_not_modifiable_lvalue, ERROR,
+ "variable is not assignable (missing __block type specifier)")
DIAG(err_typecheck_call_not_function, ERROR,
"called object is not a function or function pointer")
DIAG(err_typecheck_call_too_few_args, ERROR,
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=56652&r1=56651&r2=56652&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Sep 26 09:41:28 2008
@@ -425,7 +425,7 @@
}
case BlockDeclRefExprClass: {
const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
- if (BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
+ if (isa<VarDecl>(BDR->getDecl()))
return LV_Valid;
break;
}
@@ -497,6 +497,15 @@
if (r->hasConstFields())
return MLV_ConstQualified;
}
+ // The following is illegal:
+ // void takeclosure(void (^C)(void));
+ // void func() { int x = 1; takeclosure(^{ x = 7 }); }
+ //
+ if (getStmtClass() == BlockDeclRefExprClass) {
+ const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
+ if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
+ return MLV_NotBlockQualified;
+ }
return MLV_Valid;
}
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=56652&r1=56651&r2=56652&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Sep 26 09:41:28 2008
@@ -2181,6 +2181,10 @@
Diag(loc, diag::err_typecheck_duplicate_vector_components_not_mlvalue,
lex->getSourceRange());
return QualType();
+ case Expr::MLV_NotBlockQualified:
+ Diag(loc, diag::err_block_decl_ref_not_modifiable_lvalue,
+ lex->getSourceRange());
+ return QualType();
}
AssignConvertType ConvTy;
Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=56652&r1=56651&r2=56652&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Fri Sep 26 09:41:28 2008
@@ -39,7 +39,9 @@
}
foo:
- takeclosure(^{ x = 4; }); // expected-error {{expression is not assignable}}
+ takeclosure(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
+ __block y = 7;
+ takeclosure(^{ y = 8; });
}
@@ -52,6 +54,19 @@
void (*noop2)() = 0;
}
+void myfunc(int (^block)(int)) {}
+
+void myfunc3(int *x);
+
+void test5() {
+ int a;
+
+ myfunc(^(int abcd) {
+ myfunc3(&a);
+ return 1;
+ });
+}
+
void *X;
void test_arguments() {
More information about the cfe-commits
mailing list