]> gcc.gnu.org Git - gcc.git/commit
c++: cxx_eval_vec_init after zero-initialization [PR96282]
authorPatrick Palka <ppalka@redhat.com>
Wed, 5 Aug 2020 19:05:30 +0000 (15:05 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 21 Apr 2021 19:06:05 +0000 (15:06 -0400)
commitfef6ee0790de58f16128a0de87571ba7e04b8320
tree9d13a2ee200333d739c0b5a53350a558d724b995
parent34976f3bf8ff146e31b1ccee9351c5803604d7ae
c++: cxx_eval_vec_init after zero-initialization [PR96282]

In the first testcase below, expand_aggr_init_1 sets up t's default
constructor such that the ctor first zero-initializes the entire base b,
followed by calling b's default constructor, the latter of which just
default-initializes the array member b::m via a VEC_INIT_EXPR.

So upon constexpr evaluation of this latter VEC_INIT_EXPR, ctx->ctor is
nonempty due to the prior zero-initialization, and we proceed in
cxx_eval_vec_init to append new constructor_elts to the end of ctx->ctor
without first checking if a matching constructor_elt already exists.
This leads to ctx->ctor having two matching constructor_elts for each
index.

This patch fixes this issue by truncating a zero-initialized array
CONSTRUCTOR in cxx_eval_vec_init_1 before we begin appending array
elements to it.  We propagate its zeroed out state during evaluation by
clearing CONSTRUCTOR_NO_CLEARING on each new appended aggregate element.

gcc/cp/ChangeLog:

PR c++/96282
* constexpr.c (cxx_eval_vec_init_1): Truncate ctx->ctor and
then clear CONSTRUCTOR_NO_CLEARING on each appended element
initializer if we're initializing a previously zero-initialized
array object.

gcc/testsuite/ChangeLog:

PR c++/96282
* g++.dg/cpp0x/constexpr-array26.C: New test.
* g++.dg/cpp0x/constexpr-array27.C: New test.

Co-authored-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit d21252de6c81ed236d8981d47b9a57dc4f1c6d57)
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-array26.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-array27.C [new file with mode: 0644]
This page took 0.063057 seconds and 6 git commands to generate.