From 1e027956d0baae2fbdeff5f4b6923a4e6c3db9bb Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 12 Feb 2018 07:31:56 +0000 Subject: [PATCH] re PR c++/84281 (Heap grows indefinitely) 2018-02-12 Richard Biener PR c++/84281 * constexpr.c (cxx_eval_vec_init_1): Use a RANGE_EXPR to compact uniform constructors and delay allocating them fully. From-SVN: r257580 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b8793751b9..bb7e9173072 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-12 Richard Biener + + PR c++/84281 + * constexpr.c (cxx_eval_vec_init_1): Use a RANGE_EXPR to compact + uniform constructors and delay allocating them fully. + 2018-02-09 Jason Merrill PR c++/84036 - ICE with variadic capture. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 72924412706..d89bdd5a6a4 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2885,7 +2885,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 **p = &CONSTRUCTOR_ELTS (ctx->ctor); - vec_alloc (*p, max + 1); bool pre_init = false; unsigned HOST_WIDE_INT i; @@ -2978,13 +2977,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) -- 2.30.2