[cfe-commits] r102546 - in /cfe/trunk: lib/CodeGen/CGObjC.cpp test/CodeGenObjCXX/ivar-objects.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Apr 28 15:30:34 PDT 2010
Author: fjahanian
Date: Wed Apr 28 17:30:33 2010
New Revision: 102546
URL: http://llvm.org/viewvc/llvm-project?rev=102546&view=rev
Log:
Support for construct/destruct of ivar array
of c++ objects (NeXt runtime).
radar 7900343.
Added:
cfe/trunk/test/CodeGenObjCXX/ivar-objects.mm
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=102546&r1=102545&r2=102546&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Apr 28 17:30:33 2010
@@ -413,10 +413,9 @@
CXXBaseOrMemberInitializer *IvarInit = IvarInitializers[I];
FieldDecl *Field = IvarInit->getMember();
QualType FieldType = Field->getType();
- if (CGM.getContext().getAsConstantArrayType(FieldType))
- assert(false && "Construction objc arrays NYI");
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
- LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0);
+ LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
+ LoadObjCSelf(), Ivar, 0);
EmitAggExpr(IvarInit->getInit(), LV.getAddress(),
LV.isVolatileQualified(), false, true);
}
@@ -432,15 +431,27 @@
for (size_t i = IvarInitializers.size(); i > 0; --i) {
FieldDecl *Field = IvarInitializers[i - 1]->getMember();
QualType FieldType = Field->getType();
- if (CGM.getContext().getAsConstantArrayType(FieldType))
- assert(false && "Destructing objc arrays NYI");
+ const ConstantArrayType *Array =
+ getContext().getAsConstantArrayType(FieldType);
+ if (Array)
+ FieldType = getContext().getBaseElementType(FieldType);
+
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
LoadObjCSelf(), Ivar, 0);
const RecordType *RT = FieldType->getAs<RecordType>();
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
- EmitCXXDestructorCall(FieldClassDecl->getDestructor(CGM.getContext()),
- Dtor_Complete, LV.getAddress());
+ if (Array) {
+ const llvm::Type *BasePtr = ConvertType(FieldType);
+ BasePtr = llvm::PointerType::getUnqual(BasePtr);
+ llvm::Value *BaseAddrPtr =
+ Builder.CreateBitCast(LV.getAddress(), BasePtr);
+ EmitCXXAggrDestructorCall(FieldClassDecl->getDestructor(getContext()),
+ Array, BaseAddrPtr);
+ }
+ else
+ EmitCXXDestructorCall(FieldClassDecl->getDestructor(CGM.getContext()),
+ Dtor_Complete, LV.getAddress());
}
}
FinishFunction();
Added: cfe/trunk/test/CodeGenObjCXX/ivar-objects.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/ivar-objects.mm?rev=102546&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/ivar-objects.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/ivar-objects.mm Wed Apr 28 17:30:33 2010
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// CHECK: -[A .cxx_construct]
+// CHECK: -[A .cxx_destruct]
+
+ at interface NSObject
+- alloc;
+- init;
+- (void) release;
+ at end
+
+extern "C" int printf(const char *, ...);
+
+int count = 17;
+struct X {
+ X() : value(count++) { printf( "X::X()\n"); }
+ ~X() { printf( "X::~X()\n"); }
+ int value;
+};
+
+struct Y {
+ Y() : value(count++) { printf( "Y::Y()\n"); }
+ ~Y() { printf( "Y::~Y()\n"); }
+ int value;
+};
+
+ at interface Super : NSObject {
+ Y yvar;
+ Y yvar1;
+ Y ya[3];
+}
+- (void)finalize;
+ at end
+
+ at interface A : Super {
+ X xvar;
+ X xvar1;
+ X xvar2;
+ X xa[2][2];
+}
+
+- (void)print;
+- (void)finalize;
+ at end
+
+ at implementation Super
+- (void)print {
+ printf( "yvar.value = %d\n", yvar.value);
+ printf( "yvar1.value = %d\n", yvar1.value);
+ printf( "ya[0..2] = %d %d %d\n", ya[0].value, ya[1].value, ya[2].value);
+}
+- (void)finalize {}
+ at end
+
+ at implementation A
+- (void)print {
+ printf( "xvar.value = %d\n", xvar.value);
+ printf( "xvar1.value = %d\n", xvar1.value);
+ printf( "xvar2.value = %d\n", xvar2.value);
+ printf( "xa[0..1][0..1] = %d %d %d %d\n",
+ xa[0][0].value, xa[0][1].value, xa[1][0].value, xa[1][1].value);
+ [super print];
+}
+- (void)finalize { [super finalize]; }
+ at end
+
+int main() {
+ A *a = [[A alloc] init];
+ [a print];
+ [a release];
+}
+
More information about the cfe-commits
mailing list