[cfe-commits] r82090 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/objc-assign-ivar.m
Fariborz Jahanian
fjahanian at apple.com
Wed Sep 16 16:11:23 PDT 2009
Author: fjahanian
Date: Wed Sep 16 18:11:23 2009
New Revision: 82090
URL: http://llvm.org/viewvc/llvm-project?rev=82090&view=rev
Log:
patch for generating objc'2 objc_assign_ivar. WIP.
Added:
cfe/trunk/test/CodeGenObjC/objc-assign-ivar.m
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=82090&r1=82089&r2=82090&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Sep 16 18:11:23 2009
@@ -492,17 +492,9 @@
// load of a __strong object.
llvm::Value *LvalueDst = Dst.getAddress();
llvm::Value *src = Src.getScalarVal();
-#if 0
- // FIXME: We cannot positively determine if we have an 'ivar' assignment,
- // object assignment or an unknown assignment. For now, generate call to
- // objc_assign_strongCast assignment which is a safe, but consevative
- // assumption.
if (Dst.isObjCIvar())
CGM.getObjCRuntime().EmitObjCIvarAssign(*this, src, LvalueDst);
- else
- CGM.getObjCRuntime().EmitObjCGlobalAssign(*this, src, LvalueDst);
-#endif
- if (Dst.isGlobalObjCRef())
+ else if (Dst.isGlobalObjCRef())
CGM.getObjCRuntime().EmitObjCGlobalAssign(*this, src, LvalueDst);
else
CGM.getObjCRuntime().EmitObjCStrongCastAssign(*this, src, LvalueDst);
@@ -703,6 +695,10 @@
!Ctx.getLangOptions().ObjCNewGCAPI)
return;
+ if (isa<ObjCIvarRefExpr>(E)) {
+ LV.SetObjCIvar(LV, true);
+ return;
+ }
if (const DeclRefExpr *Exp = dyn_cast<DeclRefExpr>(E)) {
if (const VarDecl *VD = dyn_cast<VarDecl>(Exp->getDecl())) {
if ((VD->isBlockVarDecl() && !VD->hasLocalStorage()) ||
@@ -1033,7 +1029,6 @@
LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
bool isUnion = false;
- bool isIvar = false;
bool isNonGC = false;
Expr *BaseExpr = E->getBase();
llvm::Value *BaseValue = NULL;
@@ -1057,8 +1052,6 @@
CVRQualifiers = BaseExpr->getType().getCVRQualifiers();
} else {
LValue BaseLV = EmitLValue(BaseExpr);
- if (BaseLV.isObjCIvar())
- isIvar = true;
if (BaseLV.isNonGC())
isNonGC = true;
// FIXME: this isn't right for bitfields.
@@ -1074,7 +1067,6 @@
assert(Field && "No code generation for non-field member references");
LValue MemExpLV = EmitLValueForField(BaseValue, Field, isUnion,
CVRQualifiers);
- LValue::SetObjCIvar(MemExpLV, isIvar);
LValue::SetObjCNonGC(MemExpLV, isNonGC);
setObjCGCLValueClass(getContext(), E, MemExpLV);
return MemExpLV;
@@ -1425,7 +1417,10 @@
CVRQualifiers = ObjectTy.getCVRQualifiers();
}
- return EmitLValueForIvar(ObjectTy, BaseValue, E->getDecl(), CVRQualifiers);
+ LValue LV =
+ EmitLValueForIvar(ObjectTy, BaseValue, E->getDecl(), CVRQualifiers);
+ setObjCGCLValueClass(getContext(), E, LV);
+ return LV;
}
LValue
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=82090&r1=82089&r2=82090&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Wed Sep 16 18:11:23 2009
@@ -129,7 +129,6 @@
LValue LV = LValue::MakeAddr(V, IvarTy.getCVRQualifiers()|CVRQualifiers,
CGF.CGM.getContext().getObjCGCAttrKind(IvarTy));
- LValue::SetObjCIvar(LV, true);
return LV;
}
Added: cfe/trunk/test/CodeGenObjC/objc-assign-ivar.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc-assign-ivar.m?rev=82090&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc-assign-ivar.m (added)
+++ cfe/trunk/test/CodeGenObjC/objc-assign-ivar.m Wed Sep 16 18:11:23 2009
@@ -0,0 +1,47 @@
+// RUN: clang-cc -fnext-runtime -fobjc-gc -fobjc-newgc-api -emit-llvm -o %t %s &&
+// RUN: grep -F '@objc_assign_ivar' %t | count 11 &&
+// RUN: true
+
+typedef struct {
+ id element;
+ id elementArray[10];
+ __strong id cfElement;
+ __strong id cfElementArray[10];
+} struct_with_ids_t;
+
+
+ at interface NSString @end
+
+ at interface Foo {
+ at public
+// assignments to any/all of these fields should generate objc_assign_ivar
+ __strong id dict;
+ __strong id dictArray[3];
+ id ivar;
+ id array[10];
+ id nsobject;
+ NSString *stringArray[10];
+ struct_with_ids_t inner;
+}
+ at end
+
+// The test cases
+int IvarAssigns;
+void *rhs = 0;
+#define ASSIGNTEST(expr, global) expr = rhs
+
+void testIvars() {
+ Foo *foo;
+ ASSIGNTEST(foo->ivar, IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->dict, IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->dictArray[0], IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->array[0], IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->nsobject, IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->stringArray[0], IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->inner.element, IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->inner.elementArray[0], IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->inner.cfElement, IvarAssigns); // objc_assign_ivar
+ ASSIGNTEST(foo->inner.cfElementArray[0], IvarAssigns); // objc_assign_ivar
+
+}
+
More information about the cfe-commits
mailing list