[cfe-commits] r70939 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGValue.h test/CodeGenObjC/objc2-assign-global.m
Fariborz Jahanian
fjahanian at apple.com
Mon May 4 16:27:20 PDT 2009
Author: fjahanian
Date: Mon May 4 18:27:20 2009
New Revision: 70939
URL: http://llvm.org/viewvc/llvm-project?rev=70939&view=rev
Log:
Provide basic support for generation of objc2's
objc_assign_global API when assigning to global
objective-c object pointer.
Added:
cfe/trunk/test/CodeGenObjC/objc2-assign-global.m
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGValue.h
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=70939&r1=70938&r2=70939&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon May 4 18:27:20 2009
@@ -442,7 +442,10 @@
else
CGM.getObjCRuntime().EmitObjCGlobalAssign(*this, src, LvalueDst);
#endif
- CGM.getObjCRuntime().EmitObjCStrongCastAssign(*this, src, LvalueDst);
+ if (Dst.isGlobalObjCRef())
+ CGM.getObjCRuntime().EmitObjCGlobalAssign(*this, src, LvalueDst);
+ else
+ CGM.getObjCRuntime().EmitObjCStrongCastAssign(*this, src, LvalueDst);
return;
}
@@ -666,6 +669,8 @@
LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
E->getType().getCVRQualifiers(),
getContext().getObjCGCAttrKind(E->getType()));
+ if (LV.isObjCStrong())
+ LV.SetGlobalObjCRef(LV, true);
return LV;
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),
Modified: cfe/trunk/lib/CodeGen/CGValue.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGValue.h?rev=70939&r1=70938&r2=70939&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGValue.h (original)
+++ cfe/trunk/lib/CodeGen/CGValue.h Mon May 4 18:27:20 2009
@@ -149,8 +149,12 @@
// variable.
bool NonGC: 1;
+ // Lvalue is a global reference of an objective-c object
+ bool GlobalObjCRef : 1;
+
// objective-c's gc attributes
unsigned ObjCType : 2;
+
private:
@@ -160,7 +164,7 @@
// FIXME: Convenient place to set objc flags to 0. This
// should really be done in a user-defined constructor instead.
R.ObjCType = None;
- R.Ivar = R.NonGC = false;
+ R.Ivar = R.NonGC = R.GlobalObjCRef = false;
}
public:
@@ -180,12 +184,17 @@
bool isObjCIvar() const { return Ivar; }
bool isNonGC () const { return NonGC; }
+ bool isGlobalObjCRef() const { return GlobalObjCRef; }
bool isObjCWeak() const { return ObjCType == Weak; }
bool isObjCStrong() const { return ObjCType == Strong; }
static void SetObjCIvar(LValue& R, bool iValue) {
R.Ivar = iValue;
}
+
+ static void SetGlobalObjCRef(LValue& R, bool iValue) {
+ R.GlobalObjCRef = iValue;
+ }
static void SetObjCNonGC(LValue& R, bool iValue) {
R.NonGC = iValue;
Added: cfe/trunk/test/CodeGenObjC/objc2-assign-global.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-assign-global.m?rev=70939&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-assign-global.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc2-assign-global.m Mon May 4 18:27:20 2009
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fnext-runtime -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep -F '@objc_assign_global' %t | count 2 &&
+// RUN: true
+id a;
+int main() {
+ a = 0;
+}
+
More information about the cfe-commits
mailing list