summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-09-23 18:57:30 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-09-23 18:57:30 +0000
commitc367b8f8cc2352430f434254ee4d6b23d6af59a9 (patch)
treecf555e0a40eeddd8fe472396ca858a6cfdfcce07
parent947961c15120b6630af3ac59221273d26ac84d39 (diff)
downloadbcm5719-llvm-c367b8f8cc2352430f434254ee4d6b23d6af59a9.tar.gz
bcm5719-llvm-c367b8f8cc2352430f434254ee4d6b23d6af59a9.zip
objc-gc: Fix a corner case where clang fails to generate GC
write barrier with captured pointer to object. // rdar://10150823 llvm-svn: 140399
-rw-r--r--clang/lib/AST/Expr.cpp9
-rw-r--r--clang/test/CodeGenObjC/objc2-strong-cast-block-import.m25
2 files changed, 33 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a358693a52c..ba191a8c80b 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1728,8 +1728,15 @@ bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const {
->isOBJCGCCandidate(Ctx);
case CStyleCastExprClass:
return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
+ case BlockDeclRefExprClass:
case DeclRefExprClass: {
- const Decl *D = cast<DeclRefExpr>(E)->getDecl();
+
+ const Decl *D;
+ if (const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E))
+ D = BDRE->getDecl();
+ else
+ D = cast<DeclRefExpr>(E)->getDecl();
+
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
if (VD->hasGlobalStorage())
return true;
diff --git a/clang/test/CodeGenObjC/objc2-strong-cast-block-import.m b/clang/test/CodeGenObjC/objc2-strong-cast-block-import.m
new file mode 100644
index 00000000000..29218a37799
--- /dev/null
+++ b/clang/test/CodeGenObjC/objc2-strong-cast-block-import.m
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc-only -fblocks -fobjc-nonfragile-abi -emit-llvm -o - %s | FileCheck %s
+// rdar://10150823
+
+@interface Test {
+@package
+ Test ** __strong objects;
+}
+@end
+
+id newObject();
+void runWithBlock(void(^)(int i));
+
+@implementation Test
+
+- (void)testWithObjectInBlock {
+ Test **children = objects;
+ runWithBlock(^(int i){
+ children[i] = newObject();
+ });
+}
+
+@end
+// CHECK: call i8* @objc_assign_strongCast
+// CHECK: call i8* @objc_assign_strongCast
+
OpenPOWER on IntegriCloud