aboutsummaryrefslogtreecommitdiff
path: root/lib/Rewrite/RewriteObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-02-16 22:37:10 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-02-16 22:37:10 +0000
commit05318d835e8beb16ac6bdd2c0db0ab6a922f35cf (patch)
treeea4f874df1f47eec3297f9dd28c10fb1ed104282 /lib/Rewrite/RewriteObjC.cpp
parentbac77374729b3bed72f41b66cd80d6e0d38ace3b (diff)
Block rewriting bug. Don't take address of captured
byref variables again when passing them to inner blocks. // rdar://9006279 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125690 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/RewriteObjC.cpp')
-rw-r--r--lib/Rewrite/RewriteObjC.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp
index 543439aac1..1e9b9d3033 100644
--- a/lib/Rewrite/RewriteObjC.cpp
+++ b/lib/Rewrite/RewriteObjC.cpp
@@ -5269,6 +5269,7 @@ FunctionDecl *RewriteObjC::SynthBlockInitFunctionDecl(llvm::StringRef name) {
Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
const llvm::SmallVector<BlockDeclRefExpr *, 8> &InnerBlockDeclRefs) {
+ const BlockDecl *block = Exp->getBlockDecl();
Blocks.push_back(Exp);
CollectBlockDeclRefInfo(Exp);
@@ -5412,7 +5413,22 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
FD = SynthBlockInitFunctionDecl((*I)->getName());
Exp = new (Context) DeclRefExpr(FD, FD->getType(), VK_LValue,
SourceLocation());
- Exp = new (Context) UnaryOperator(Exp, UO_AddrOf,
+ bool isNestedCapturedVar = false;
+ if (block)
+ for (BlockDecl::capture_const_iterator ci = block->capture_begin(),
+ ce = block->capture_end(); ci != ce; ++ci) {
+ const VarDecl *variable = ci->getVariable();
+ if (variable == ND && ci->isNested()) {
+ assert (ci->isByRef() &&
+ "SynthBlockInitExpr - captured block variable is not byref");
+ isNestedCapturedVar = true;
+ break;
+ }
+ }
+ // captured nested byref variable has its address passed. Do not take
+ // its address again.
+ if (!isNestedCapturedVar)
+ Exp = new (Context) UnaryOperator(Exp, UO_AddrOf,
Context->getPointerType(Exp->getType()),
VK_RValue, OK_Ordinary, SourceLocation());
Exp = NoTypeInfoCStyleCastExpr(Context, castT, CK_BitCast, Exp);