]> granicus.if.org Git - clang/commitdiff
Fix a bug where write-barriers for assignment through reference
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Nov 2010 22:39:16 +0000 (22:39 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 18 Nov 2010 22:39:16 +0000 (22:39 +0000)
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

lib/CodeGen/CGExpr.cpp
test/CodeGenObjCXX/refence-assign-write-barrier.mm [new file with mode: 0644]

index 6bfafca857e71263037e88ac72d8c4ea0f45457d..286665da86737d7aac2fa0ffcae26ce328d60ea1 100644 (file)
@@ -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 (file)
index 0000000..b295eb2
--- /dev/null
@@ -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}}