From 59a53fa3f8ea73bae52ea36d0038f76e9f10729c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 16 Sep 2009 18:09:18 +0000 Subject: [PATCH] Do not generate write-barrier in indirect assignment to a weak object. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82061 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 6 ++++-- test/CodeGenObjC/objc2-weak-assign.m | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 0ac896c783..4f2d47ec2f 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1117,8 +1117,10 @@ bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { if (VD->hasGlobalStorage()) return true; QualType T = VD->getType(); - // dereferencing to a pointer is always a gc'able candidate - return T->isPointerType(); + // dereferencing to a pointer is always a gc'able candidate, + // unless it is __weak. + return T->isPointerType() && + (Ctx.getObjCGCAttrKind(T) != QualType::Weak); } return false; } diff --git a/test/CodeGenObjC/objc2-weak-assign.m b/test/CodeGenObjC/objc2-weak-assign.m index a3740b207e..635ca38df4 100644 --- a/test/CodeGenObjC/objc2-weak-assign.m +++ b/test/CodeGenObjC/objc2-weak-assign.m @@ -9,6 +9,10 @@ __weak id* a1[20]; id* __weak a2[30]; id** __weak a3[40]; +void foo (__weak id *param) { + *param = 0; +} + int main() { *x = 0; -- 2.40.0