[cfe-commits] r86849 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/array-value-initialize.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Nov 11 09:55:25 PST 2009
Author: fjahanian
Date: Wed Nov 11 11:55:25 2009
New Revision: 86849
URL: http://llvm.org/viewvc/llvm-project?rev=86849&view=rev
Log:
Value initialize non-class array members in ctor's
initializer list. Fixes PR5463.
Added:
cfe/trunk/test/CodeGenCXX/array-value-initialize.cpp
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=86849&r1=86848&r2=86849&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Nov 11 11:55:25 2009
@@ -1511,7 +1511,14 @@
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
Added: cfe/trunk/test/CodeGenCXX/array-value-initialize.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/array-value-initialize.cpp?rev=86849&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/array-value-initialize.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/array-value-initialize.cpp Wed Nov 11 11:55:25 2009
@@ -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;
+}
+
More information about the cfe-commits
mailing list