c++: non-dep array new-expr size [PR111929]
commitd80a26cca025877b7657fa355570bc301223b50b
authorPatrick Palka <ppalka@redhat.com>
Tue, 24 Oct 2023 22:03:17 +0000 (24 18:03 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 24 Oct 2023 22:03:17 +0000 (24 18:03 -0400)
tree56306d3e0dd6a08f6175269cbbc3cb140f016f7c
parent51f164f76212feaf896d65616f60877d3217b701
c++: non-dep array new-expr size [PR111929]

This PR is another instance of NON_DEPENDENT_EXPR having acted as an
"analysis barrier" for middle-end routines, and now that it's gone we're
more prone to passing weird templated trees (that have a generic tree
code) to middle-end routines which end up ICEing on such trees.

In the testcase below the non-dependent array new-expr size 'x + 42' is
expressed as an ordinary PLUS_EXPR, but whose operands have different
types (since templated trees encode just the syntactic form of an
expression devoid of e.g. implicit conversions).  This type incoherency
triggers an ICE from size_binop in build_new_1 due to a wide_int assert
that expects the operand types to have the same precision.

This patch fixes this by replacing our piecemeal folding of 'size' in
build_new_1 with a single call to cp_fully_fold (which is a no-op in a
template context) once 'size' is built up.

PR c++/111929

gcc/cp/ChangeLog:

* init.cc (build_new_1): Use convert, build2, build3 and
cp_fully_fold instead of fold_convert, size_binop and
fold_build3 when building up 'size'.

gcc/testsuite/ChangeLog:

* g++.dg/template/non-dependent28.C: New test.
gcc/cp/init.cc
gcc/testsuite/g++.dg/template/non-dependent28.C [new file with mode: 0644]