This fixes <rdar://problem/
6248392> clang: Error when using address of stack variable inside block.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56652
91177308-0d34-0410-b5e6-
96231b3b80d8
MLV_InvalidExpression,
MLV_IncompleteType,
MLV_ConstQualified,
- MLV_ArrayType
+ MLV_ArrayType,
+ MLV_NotBlockQualified
};
isModifiableLvalueResult isModifiableLvalue(ASTContext &Ctx) const;
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,
}
case BlockDeclRefExprClass: {
const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
- if (BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
+ if (isa<VarDecl>(BDR->getDecl()))
return LV_Valid;
break;
}
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;
}
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;
}
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; });
}
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() {