Value initialize non-class array members in ctor's

initializer list. Fixes PR5463.

llvm-svn: 86849
This commit is contained in:
Fariborz Jahanian 2009-11-11 17:55:25 +00:00
parent 7a09964e81
commit 03f62ed9bb
2 changed files with 36 additions and 1 deletions

View File

@ -1511,7 +1511,14 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
RHS = RValue::get(CGF.CGM.EmitConstantExpr(RhsExpr, FieldType, &CGF));
else
RHS = RValue::get(CGF.EmitScalarExpr(RhsExpr, true));
CGF.EmitStoreThroughLValue(RHS, LHS, FieldType);
if (Array && !FieldType->getAs<RecordType>()) {
// value initialize a non-class array data member using arr() syntax in
// initializer list.
QualType Ty = CGF.getContext().getCanonicalType((Field)->getType());
CGF.EmitMemSetToZero(LHS.getAddress(), Ty);
}
else
CGF.EmitStoreThroughLValue(RHS, LHS, FieldType);
}
/// EmitCtorPrologue - This routine generates necessary code to initialize

View File

@ -0,0 +1,28 @@
// RUN: clang-cc -emit-llvm -o - %s
// PR5463
extern "C" int printf(...);
struct S {
double filler;
};
struct Foo {
Foo(void) : bar_(), dbar_(), sbar_() {
for (int i = 0; i < 5; i++) {
printf("bar_[%d] = %d\n", i, bar_[i]);
printf("dbar_[%d] = %f\n", i, dbar_[i]);
printf("sbar_[%d].filler = %f\n", i, sbar_[i].filler);
}
}
int bar_[5];
double dbar_[5];
S sbar_[5];
};
int main(void)
{
Foo a;
}