]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/84281 (Heap grows indefinitely)
authorRichard Biener <rguenther@suse.de>
Mon, 26 Nov 2018 15:53:48 +0000 (15:53 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 26 Nov 2018 15:53:48 +0000 (10:53 -0500)
PR c++/84281

2018-02-12  Richard Biener  <rguenther@suse.de>

* constexpr.c (cxx_eval_vec_init_1): Use a RANGE_EXPR to compact
uniform constructors and delay allocating them fully.

From-SVN: r266469

gcc/cp/ChangeLog
gcc/cp/constexpr.c

index 3392176ce26dacbc0a13878ec6c82ed600b393f2..03c30c3b1229a92726ab369ed8b6266bdf1eb684 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-26  Richard Biener  <rguenther@suse.de>
+
+       PR c++/84281
+       * constexpr.c (cxx_eval_vec_init_1): Use a RANGE_EXPR to compact
+       uniform constructors and delay allocating them fully.
+
 2018-11-26  Jason Merrill  <jason@redhat.com>
 
        PR c++/87075 - ICE with constexpr array initialization.
index 48e821903ac02c99b5c754b43218bc2f67a305b7..cfd6a3a0e6e19893f950ff54159cab0c9d1adf70 100644 (file)
@@ -2843,7 +2843,6 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
   unsigned HOST_WIDE_INT max = tree_to_uhwi (array_type_nelts_top (atype));
   verify_ctor_sanity (ctx, atype);
   vec<constructor_elt, va_gc> **p = &CONSTRUCTOR_ELTS (ctx->ctor);
-  vec_alloc (*p, max + 1);
   bool pre_init = false;
   unsigned HOST_WIDE_INT i;
 
@@ -2939,13 +2938,14 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
        {
          if (new_ctx.ctor != ctx->ctor)
            eltinit = new_ctx.ctor;
-         for (i = 1; i < max; ++i)
-           {
-             idx = build_int_cst (size_type_node, i);
-             CONSTRUCTOR_APPEND_ELT (*p, idx, unshare_constructor (eltinit));
-           }
+         tree range = build2 (RANGE_EXPR, size_type_node,
+                              build_int_cst (size_type_node, 1),
+                              build_int_cst (size_type_node, max - 1));
+         CONSTRUCTOR_APPEND_ELT (*p, range, unshare_constructor (eltinit));
          break;
        }
+      else if (i == 0)
+       vec_safe_reserve (*p, max);
     }
 
   if (!*non_constant_p)