diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-01-13 20:00:54 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-01-13 20:00:54 +0000 |
commit | ec8051276e5ba5eb3f8dcb0ebb96e17495cbc2bf (patch) | |
tree | f0418b7083045873e6f9536c68c9425968ee08f5 | |
parent | 14110477887e3dc168ffc6c191e72d705051f99e (diff) |
Generate write-barriers for global objc
assigns. // rdar://8761767
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123391 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGDeclCXX.cpp | 10 | ||||
-rw-r--r-- | test/CodeGenObjCXX/write-barrier-global-assign.mm | 29 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 17571fccf0..84e03446f6 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -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 index 0000000000..a14804ffe1 --- /dev/null +++ b/test/CodeGenObjCXX/write-barrier-global-assign.mm @@ -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; +} |