From: Richard Biener Date: Thu, 2 Feb 2017 08:55:44 +0000 (+0000) Subject: re PR c++/14179 (out of memory while parsing array with many initializers) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=27de0fab0f2aed57cd81d9bfefa913b2665b5b88;p=gcc.git re PR c++/14179 (out of memory while parsing array with many initializers) 2017-02-02 Richard Biener PR cp/14179 * cp-gimplify.c (cp_fold): When folding a CONSTRUCTOR copy it lazily on the first changed element only and copy it fully upfront, only storing changed elements. From-SVN: r245118 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fbea09af7fc..96136af87eb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2017-02-02 Richard Biener + + PR cp/14179 + * cp-gimplify.c (cp_fold): When folding a CONSTRUCTOR copy + it lazily on the first changed element only and copy it + fully upfront, only storing changed elements. + 2017-02-02 Paolo Carlini PR c++/69637 diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 13647033f70..3eec9400fb0 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2358,30 +2358,26 @@ cp_fold (tree x) { unsigned i; constructor_elt *p; - bool changed = false; vec *elts = CONSTRUCTOR_ELTS (x); vec *nelts = NULL; - vec_safe_reserve (nelts, vec_safe_length (elts)); FOR_EACH_VEC_SAFE_ELT (elts, i, p) { tree op = cp_fold (p->value); - constructor_elt e = { p->index, op }; - nelts->quick_push (e); if (op != p->value) { if (op == error_mark_node) { x = error_mark_node; - changed = false; + vec_free (nelts); break; } - changed = true; + if (nelts == NULL) + nelts = elts->copy (); + (*nelts)[i].value = op; } } - if (changed) + if (nelts) x = build_constructor (TREE_TYPE (x), nelts); - else - vec_free (nelts); break; } case TREE_VEC: