]> granicus.if.org Git - clang/commitdiff
Generate write-barriers for global objc
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 13 Jan 2011 20:00:54 +0000 (20:00 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 13 Jan 2011 20:00:54 +0000 (20:00 +0000)
assigns. // rdar://8761767

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

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

index 17571fccf08546001c009425e63c7269e57fd422..84e03446f667ff0a3ddf04c2ba9f5323c4fff726 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "CodeGenFunction.h"
+#include "CGObjCRuntime.h"
 #include "CGCXXABI.h"
 #include "clang/Frontend/CodeGenOptions.h"
 #include "llvm/Intrinsics.h"
@@ -34,7 +35,14 @@ static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D,
   unsigned Alignment = Context.getDeclAlign(&D).getQuantity();
   if (!CGF.hasAggregateLLVMType(T)) {
     llvm::Value *V = CGF.EmitScalarExpr(Init);
-    CGF.EmitStoreOfScalar(V, DeclPtr, isVolatile, Alignment, T);
+    CodeGenModule &CGM = CGF.CGM;
+    if (CGF.getContext().getObjCGCAttrKind(T) == Qualifiers::Strong)
+      CGM.getObjCRuntime().EmitObjCGlobalAssign(CGF, V, DeclPtr,
+                                                D.isThreadSpecified());
+    else if (CGF.getContext().getObjCGCAttrKind(T) == Qualifiers::Weak)
+      CGM.getObjCRuntime().EmitObjCWeakAssign(CGF, V, DeclPtr);
+    else
+      CGF.EmitStoreOfScalar(V, DeclPtr, isVolatile, Alignment, T);
   } else if (T->isAnyComplexType()) {
     CGF.EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
   } else {
diff --git a/test/CodeGenObjCXX/write-barrier-global-assign.mm b/test/CodeGenObjCXX/write-barrier-global-assign.mm
new file mode 100644 (file)
index 0000000..a14804f
--- /dev/null
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
+// rdar://8761767
+
+@class CPDestUser;
+
+CPDestUser* FUNC();
+
+// CHECK: {{call.* @objc_assign_global}}
+CPDestUser* globalUser = FUNC();
+
+// CHECK: {{call.* @objc_assign_weak}}
+__weak CPDestUser* weakUser = FUNC();
+
+
+// CHECK: {{call.* @objc_assign_global}}
+static CPDestUser* staticUser = FUNC();
+
+CPDestUser* GetDestUser()
+{
+// CHECK: {{call.* @objc_assign_global}}
+       static CPDestUser* gUser = FUNC();
+// CHECK: {{call.* @objc_assign_weak}}
+       static __weak CPDestUser* wUser = FUNC();
+        if (wUser)
+          return wUser;
+        if (staticUser)
+         return staticUser;
+       return gUser;
+}