From: Nathan Sidwell Date: Thu, 9 Dec 2004 12:21:32 +0000 (+0000) Subject: re PR c++/16681 (array initialization in struct construct is a memory hog) X-Git-Tag: releases/gcc-3.4.4~433 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f57b1d397ac8d26999f4c0db0e230635161d5fcd;p=thirdparty%2Fgcc.git re PR c++/16681 (array initialization in struct construct is a memory hog) cp: PR c++/16681 * init.c (build_zero_init): Build a RANGE_EXPR for an array initializer. testsuite: PR c++/16681 * g++.dg/init/array15.C: New. * g++.dg/init/array16.C: New. From-SVN: r91934 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6094afa75aee..205348700208 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-12-09 Nathan Sidwell + + PR c++/16681 + * init.c (build_zero_init): Build a RANGE_EXPR for an array + initializer. + 2004-12-08 Kriang Lerdsuwanakij PR c++/18100 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 7f974bf7132c..3adf37fb97bf 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -217,7 +217,6 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) } else if (TREE_CODE (type) == ARRAY_TYPE) { - tree index; tree max_index; tree inits; @@ -231,14 +230,16 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) /* A zero-sized array, which is accepted as an extension, will have an upper bound of -1. */ if (!tree_int_cst_equal (max_index, integer_minus_one_node)) - for (index = size_zero_node; - !tree_int_cst_lt (max_index, index); - index = size_binop (PLUS_EXPR, index, size_one_node)) - inits = tree_cons (index, - build_zero_init (TREE_TYPE (type), - /*nelts=*/NULL_TREE, - static_storage_p), - inits); + { + tree elt_init = build_zero_init (TREE_TYPE (type), + /*nelts=*/NULL_TREE, + static_storage_p); + tree range = build (RANGE_EXPR, + sizetype, size_zero_node, max_index); + + inits = tree_cons (range, elt_init, inits); + } + CONSTRUCTOR_ELTS (init) = nreverse (inits); } else if (TREE_CODE (type) == REFERENCE_TYPE) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9389ff2efc84..b3f35f489274 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-12-09 Nathan Sidwell + + PR c++/16681 + * g++.dg/init/array15.C: New. + * g++.dg/init/array16.C: New. + 2004-12-08 Kriang Lerdsuwanakij PR c++/18100