diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-23 18:57:30 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-23 18:57:30 +0000 |
commit | e3f834950801f1334f1b3f3f7e9a34062905fe1d (patch) | |
tree | 54836f79c99733e468c513de1b4bd642d023b3d4 | |
parent | 966a8a5fdc9266152cc099ac7279e3d1f989b0fb (diff) |
objc-gc: Fix a corner case where clang fails to generate GC
write barrier with captured pointer to object. // rdar://10150823
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140399 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/Expr.cpp | 9 | ||||
-rw-r--r-- | test/CodeGenObjC/objc2-strong-cast-block-import.m | 25 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index a358693a52..ba191a8c80 100644 --- a/lib/AST/Expr.cpp +++ b/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/test/CodeGenObjC/objc2-strong-cast-block-import.m b/test/CodeGenObjC/objc2-strong-cast-block-import.m new file mode 100644 index 0000000000..29218a3779 --- /dev/null +++ b/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 + |