aboutsummaryrefslogtreecommitdiff
path: root/gcc/range-op-float.cc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2023-07-21 17:48:37 -0400
committerMarek Polacek <polacek@redhat.com>2023-07-25 11:30:19 -0400
commit6e424febfbcb27c21a7fe3a137e614765f9cf9d2 (patch)
tree259529bacee7d36cdd54ea94abc9164727744f27 /gcc/range-op-float.cc
parent09dda270380fe13e7b4722305cb1122df1f779a0 (diff)
downloadgcc-6e424febfbcb27c21a7fe3a137e614765f9cf9d2.zip
gcc-6e424febfbcb27c21a7fe3a137e614765f9cf9d2.tar.gz
gcc-6e424febfbcb27c21a7fe3a137e614765f9cf9d2.tar.bz2
c++: fix ICE with constexpr ARRAY_REF [PR110382]
This code in cxx_eval_array_reference has been hard to get right. In r12-2304 I added some code; in r13-5693 I removed some of it. Here the problematic line is "S s = arr[0];" which causes a crash on the assert in verify_ctor_sanity: gcc_assert (!ctx->object || !DECL_P (ctx->object) || ctx->global->get_value (ctx->object) == ctx->ctor); ctx->object is the VAR_DECL 's', which is correct here. The second line points to the problem: we replaced ctx->ctor in cxx_eval_array_reference: new_ctx.ctor = build_constructor (elem_type, NULL); // #1 which I think we shouldn't have; the CONSTRUCTOR we created in cxx_eval_constant_expression/DECL_EXPR new_ctx.ctor = build_constructor (TREE_TYPE (r), NULL); had the right type. We still need #1 though. E.g., in constexpr-96241.C, we never set ctx.ctor/object before calling cxx_eval_array_reference, so we have to build a CONSTRUCTOR there. And in constexpr-101371-2.C we have a ctx.ctor, but it has the wrong type, so we need a new one. We can fix the problem by always clearing the object, and, as an optimization, only create/free a new ctor when actually needed. PR c++/110382 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_array_reference): Create a new constructor only when we don't already have a matching one. Clear the object when the type is non-scalar. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-110382.C: New test.
Diffstat (limited to 'gcc/range-op-float.cc')
0 files changed, 0 insertions, 0 deletions