More work toward initialization of objects
in constructors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76980 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 4d861be..7bbc76c 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -389,7 +389,8 @@
if (NumArgs > 0) {
this->NumArgs = NumArgs;
- this->Args = new Expr*[NumArgs];
+ // FIXME. Allocation via Context
+ this->Args = new Stmt*[NumArgs];
for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
this->Args[Idx] = Args[Idx];
}
@@ -406,7 +407,7 @@
if (NumArgs > 0) {
this->NumArgs = NumArgs;
- this->Args = new Expr*[NumArgs];
+ this->Args = new Stmt*[NumArgs];
for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
this->Args[Idx] = Args[Idx];
}
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index fcc623e..589cdec 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -346,7 +346,8 @@
CXXBaseOrMemberInitializer * BMInitializer = (*B);
if (B != CDecl->init_begin())
Out << ", ";
- bool hasArguments = (BMInitializer->begin() != BMInitializer->end());
+ bool hasArguments = (BMInitializer->arg_begin() !=
+ BMInitializer->arg_end());
if (BMInitializer->isMemberInitializer()) {
FieldDecl *FD = BMInitializer->getMember();
Out << FD->getNameAsString();
@@ -360,12 +361,12 @@
}
if (hasArguments) {
Out << "(";
- for (CXXBaseOrMemberInitializer::arg_const_iterator BE =
- BMInitializer->begin(), EE = BMInitializer->end();
- BE != EE; BE++) {
- if (BE != BMInitializer->begin())
+ for (CXXBaseOrMemberInitializer::const_arg_iterator BE =
+ BMInitializer->const_arg_begin(),
+ EE = BMInitializer->const_arg_end(); BE != EE; ++BE) {
+ if (BE != BMInitializer->const_arg_begin())
Out<< ", ";
- Expr *Exp = (*BE);
+ const Expr *Exp = (*BE);
Exp->printPretty(Out, Context, 0, Policy, Indentation);
}
Out << ")";
diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp
index 4a2db05..2349171 100644
--- a/lib/CodeGen/CGCXX.cpp
+++ b/lib/CodeGen/CGCXX.cpp
@@ -432,13 +432,22 @@
QualType FieldType = getContext().getCanonicalType((Field)->getType());
assert(!getContext().getAsArrayType(FieldType)
&& "FIXME. Field arrays initialization unsupported");
- assert(!FieldType->getAsRecordType()
- && "FIXME. Field class initialization unsupported");
+
llvm::Value *LoadOfThis = LoadCXXThis();
LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
+ if (FieldType->getAsRecordType()) {
+
+ assert(Member->getConstructor() &&
+ "EmitCtorPrologue - no constructor to initialize member");
+ EmitCXXConstructorCall(Member->getConstructor(),
+ Ctor_Complete, LHS.getAddress(),
+ Member->const_arg_begin(),
+ Member->const_arg_end());
+ continue;
+ }
assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only");
- Expr *RhsExpr = *Member->begin();
+ Expr *RhsExpr = *Member->arg_begin();
llvm::Value *RHS = EmitScalarExpr(RhsExpr, true);
if (LHS.isBitfield())
EmitStoreThroughBitfieldLValue(RValue::get(RHS), LHS, FieldType, 0);