From: Fariborz Jahanian Date: Thu, 18 Nov 2010 22:39:16 +0000 (+0000) Subject: Fix a bug where write-barriers for assignment through reference X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a762514563bcbf52a016f7e6b6730cac035ac92c;p=clang Fix a bug where write-barriers for assignment through reference types was not being generated for objc pointers. // rdar://8681766. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119751 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 6bfafca857..286665da86 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1198,7 +1198,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { V = Builder.CreateLoad(V, "tmp"); LValue LV = MakeAddrLValue(V, E->getType(), Alignment); - if (NonGCable) { + if (NonGCable && !VD->getType()->isReferenceType()) { LV.getQuals().removeObjCGCAttr(); LV.setNonGC(true); } diff --git a/test/CodeGenObjCXX/refence-assign-write-barrier.mm b/test/CodeGenObjCXX/refence-assign-write-barrier.mm new file mode 100644 index 0000000000..b295eb2567 --- /dev/null +++ b/test/CodeGenObjCXX/refence-assign-write-barrier.mm @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s +// rdar://8681766 + +@interface NSArray +- (NSArray*) retain; +- (void) release; +@end + +void NSAssignArray(NSArray*& target, NSArray* newValue) +{ + if (target == newValue) + return; + + NSArray* oldValue = target; + + target = [newValue retain]; + + [oldValue release]; +} +// CHECK: {{call.* @objc_assign_strongCast}}