]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/16681 (array initialization in struct construct is a memory hog)
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 9 Dec 2004 15:09:32 +0000 (15:09 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 9 Dec 2004 15:09:32 +0000 (15:09 +0000)
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

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog

index 7aebb53aab189fee98a9715cfc60a2056ea71cd3..200b2b1867b83eea3b626c04e80fd3b26dd75bf3 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-09  Nathan Sidwell  <nathan@codesourcery.com>
+
+       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.
index f2959b6c808b4a720c0e99495a9283064b01e6fa..4d9b2440649a4efb28e8db46b7c8fbbee76bbeae 100644 (file)
@@ -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)
     ;
index f04ee9b535e818d0caad1e3ce297f27c7f144c86..9f9958a91afe64f56958c27efe83df0bb2165ba6 100644 (file)
@@ -1,3 +1,9 @@
+2004-12-09  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/16681
+       * g++.dg/init/array15.C: New.
+       * g++.dg/init/array16.C: New.
+
 2004-11-29  Roger Sayle  <roger@eyesopen.com>
 
        PR rtl-optimization/9771