]> granicus.if.org Git - clang/commitdiff
objective-C arc: in copy helper function for
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 4 Jan 2013 23:32:24 +0000 (23:32 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 4 Jan 2013 23:32:24 +0000 (23:32 +0000)
__strong __block variables, perform objc_storeStrong on
source and destination instead of direct move. This
is done with -O0 and to improve some analysis.
// rdar://12530881

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171555 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
test/CodeGenObjC/arc-unoptimized-byref-var.m [new file with mode: 0644]

index 54bcb88ce3816fd7e266495bda143ab1d606105d..e33e6644307c72f0950a752825eb5ed6b12dfc88 100644 (file)
@@ -1565,6 +1565,11 @@ public:
     llvm::Value *null =
       llvm::ConstantPointerNull::get(cast<llvm::PointerType>(value->getType()));
 
+    if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) {
+      CGF.EmitARCStoreStrongCall(destField, value, /*ignored*/ true);
+      CGF.EmitARCStoreStrongCall(srcField, null, /*ignored*/ true);
+      return;
+    }
     llvm::StoreInst *store = CGF.Builder.CreateStore(value, destField);
     store->setAlignment(Alignment.getQuantity());
 
diff --git a/test/CodeGenObjC/arc-unoptimized-byref-var.m b/test/CodeGenObjC/arc-unoptimized-byref-var.m
new file mode 100644 (file)
index 0000000..4cfc5e9
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-UNOPT %s
+// rdar://12530881
+
+void test19() {
+   __block id x;
+// CHECK-UNOPT: define internal void @__Block_byref_object_copy
+// CHECK-UNOPT: [[X:%.*]] = getelementptr inbounds [[BYREF_T:%.*]]* [[VAR:%.*]], i32 0, i32 6
+// CHECK-UNOPT: [[X2:%.*]] = getelementptr inbounds [[BYREF_T:%.*]]* [[VAR1:%.*]], i32 0, i32 6
+// CHECK-UNOPT-NEXT: [[SIX:%.*]] = load i8** [[X2]], align 8
+// CHECK-UNOPT-NEXT: call void @objc_storeStrong(i8** [[X]], i8* [[SIX]]) nounwind
+// CHECK-UNOPT-NEXT: call void @objc_storeStrong(i8** [[X2]], i8* null) nounwind
+// CHECK-UNOPT-NEXT: ret void
+}
+