diff options
| author | John McCall <rjmccall@apple.com> | 2011-07-28 07:23:35 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2011-07-28 07:23:35 +0000 |
| commit | b726a5572993e2b12442a6eed7337a311b7ebc28 (patch) | |
| tree | 3b6821dd460630a23e300f2c7529730893b42f91 /clang/lib/CodeGen | |
| parent | 3255d1d25fb3324b3be6b8612e60eb59f96aaa4c (diff) | |
| download | bcm5719-llvm-b726a5572993e2b12442a6eed7337a311b7ebc28.tar.gz bcm5719-llvm-b726a5572993e2b12442a6eed7337a311b7ebc28.zip | |
Fix a couple of problems with initialization and assignment to
__block variables where the act of initialization/assignment
itself causes the __block variable to be copied to the heap
because the variable is of block type and is being assigned
a block literal which captures the variable.
rdar://problem/9814099
llvm-svn: 136337
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGObjC.cpp | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index a372d7d6964..870fe811f14 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -507,7 +507,7 @@ void CodeGenFunction::EmitScalarInit(const Expr *init, // actually perform the initialization with an assign. bool accessedByInit = false; if (lifetime != Qualifiers::OCL_ExplicitNone) - accessedByInit = isAccessedBy(D, init); + accessedByInit = (capturedByInit || isAccessedBy(D, init)); if (accessedByInit) { LValue tempLV = lvalue; // Drill down to the __block object if necessary. diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index f81b6b75e3f..2f9ff224959 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -2144,10 +2144,20 @@ CodeGenFunction::EmitARCStoreStrong(const BinaryOperator *e, TryEmitResult result = tryEmitARCRetainScalarExpr(*this, e->getRHS()); llvm::Value *value = result.getPointer(); + bool hasImmediateRetain = result.getInt(); + + // If we didn't emit a retained object, and the l-value is of block + // type, then we need to emit the block-retain immediately in case + // it invalidates the l-value. + if (!hasImmediateRetain && e->getType()->isBlockPointerType()) { + value = EmitARCRetainBlock(value); + hasImmediateRetain = true; + } + LValue lvalue = EmitLValue(e->getLHS()); // If the RHS was emitted retained, expand this. - if (result.getInt()) { + if (hasImmediateRetain) { llvm::Value *oldValue = EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatileQualified(), lvalue.getAlignment(), e->getType(), |

