aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-patterns.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-07-13 17:16:54 -0400
committerMarek Polacek <polacek@redhat.com>2021-07-14 11:54:07 -0400
commita42f8120442cf3ba25d621bed857b5be19019d0c (patch)
tree5a44cdb1c709106fbaa38f6c13370147127403ca /gcc/tree-vect-patterns.c
parent269ca408e2839d7f3554a91515d73d4d95352f68 (diff)
downloadgcc-a42f8120442cf3ba25d621bed857b5be19019d0c.zip
gcc-a42f8120442cf3ba25d621bed857b5be19019d0c.tar.gz
gcc-a42f8120442cf3ba25d621bed857b5be19019d0c.tar.bz2
c++: constexpr array reference and value-initialization [PR101371]
This PR gave me a hard time: I saw multiple issues starting with different revisions. But ultimately the root cause seems to be the following, and the attached patch fixes all issues I've found here. In cxx_eval_array_reference we create a new constexpr context for the CP_AGGREGATE_TYPE_P case, but we also have to create it for the non-aggregate case. In this test, we are evaluating ((B *)this)->a = rhs->a which means that we set ctx.object to ((B *)this)->a. Then we proceed to evaluate the initializer, rhs->a. For *rhs, we eval rhs, a PARM_DECL, for which we have (const B &) &c.arr[0] in the hash table. Then cxx_fold_indirect_ref gives us c.arr[0]. c is evaluated to {.arr={}} so c.arr is {}. Now we want c.arr[0], so we end up in cxx_eval_array_reference and since we're initializing from {}, we call build_value_init which gives us an AGGR_INIT_EXPR that calls 'constexpr B::B()'. Then we evaluate this AGGR_INIT_EXPR and since its first argument is dummy, we take ctx.object instead. But that is the wrong object, we're not initializing ((B *)this)->a here. And so we wound up with an initializer for A, and then crash in cxx_eval_component_reference: gcc_assert (DECL_CONTEXT (part) == TYPE_MAIN_VARIANT (TREE_TYPE (whole))); where DECL_CONTEXT (part) is B (as it should be) but the type of whole was A. So create a new object, if there already was one, and the element type is not a scalar. PR c++/101371 gcc/cp/ChangeLog: * constexpr.c (cxx_eval_array_reference): Create a new .object and .ctor for the non-aggregate non-scalar case too when value-initializing. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-101371-2.C: New test. * g++.dg/cpp1y/constexpr-101371.C: New test.
Diffstat (limited to 'gcc/tree-vect-patterns.c')
0 files changed, 0 insertions, 0 deletions