]> 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 12:21:32 +0000 (12:21 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 9 Dec 2004 12:21:32 +0000 (12:21 +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: r91934

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

index 6094afa75aeec7a49493e12fa0ecb2f503e89418..20534870020885940b7943d09226fd50100ec8ed 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-12-08  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/18100
index 7f974bf7132c25e197cc5ea94f6cb8a51475ecf3..3adf37fb97bf8f9dd41e11b2d2dbcb4afc7b0a59 100644 (file)
@@ -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)
index 9389ff2efc8438181466dbeda4ef6dd90edc6c39..b3f35f489274f84af158bb046d9858b1096445c7 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-12-08  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/18100