From: Nathan Sidwell Date: Thu, 9 Dec 2004 15:09:32 +0000 (+0000) Subject: re PR c++/16681 (array initialization in struct construct is a memory hog) X-Git-Tag: releases/gcc-3.3.6~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e91e4a1bc1e079097f8a55574b61db05ec205ed9;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: r91952 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7aebb53aab18..200b2b1867b8 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-09-30 Release Manager * GCC 3.3.5 Released. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index f2959b6c808b..4d9b2440649a 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -235,7 +235,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; @@ -249,15 +248,17 @@ 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); - CONSTRUCTOR_ELTS (init) = nreverse (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 f04ee9b535e8..9f9958a91afe 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-11-29 Roger Sayle PR rtl-optimization/9771