aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-03-16 02:53:38 +0000
committerJohn McCall <rjmccall@apple.com>2011-03-16 02:53:38 +0000
commita5bcb8fec45d127501cd70fe1654b5a08a8aeb35 (patch)
tree6e8cb53d4941cf7652cba6805440ece0b5e320e0
parentd5fde2106af8e78cc1b97d6369ad0de5d0875491 (diff)
Don't emit read barriers for reading __weak __block variables
in non-GC mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127725 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprScalar.cpp6
-rw-r--r--test/CodeGenObjC/blocks.m13
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 8326dcc7a8..27b868974d 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1221,10 +1221,8 @@ Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) {
}
Value *ScalarExprEmitter::VisitBlockDeclRefExpr(const BlockDeclRefExpr *E) {
- llvm::Value *V = CGF.GetAddrOfBlockDecl(E);
- if (E->getType().isObjCGCWeak())
- return CGF.CGM.getObjCRuntime().EmitObjCWeakRead(CGF, V);
- return CGF.EmitLoadOfScalar(V, false, 0, E->getType());
+ LValue LV = CGF.EmitBlockDeclRefLValue(E);
+ return CGF.EmitLoadOfLValue(LV, E->getType()).getScalarVal();
}
//===----------------------------------------------------------------------===//
diff --git a/test/CodeGenObjC/blocks.m b/test/CodeGenObjC/blocks.m
index 06dc908f2b..151c162342 100644
--- a/test/CodeGenObjC/blocks.m
+++ b/test/CodeGenObjC/blocks.m
@@ -87,3 +87,16 @@ void test2(Test2 *x) {
__weak __block Test2 *weakX = x;
test2_helper(^{ [weakX destroy]; });
}
+
+// rdar://problem/9124263
+// In the test above, check that the use in the invocation function
+// doesn't require a read barrier.
+// CHECK: define internal void @__test2_block_invoke_
+// CHECK: [[BLOCK:%.*]] = bitcast i8* {{%.*}} to [[BLOCK_T]]*
+// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
+// CHECK-NEXT: [[T1:%.*]] = load i8** [[T0]]
+// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[WEAK_T]]*
+// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T2]], i32 0, i32 1
+// CHECK-NEXT: [[T4:%.*]] = load [[WEAK_T]]** [[T3]]
+// CHECK-NEXT: [[WEAKX:%.*]] = getelementptr inbounds [[WEAK_T]]* [[T4]], i32 0, i32 6
+// CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[WEAKX]], align 4