openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops [PR108503]
authorJakub Jelinek <jakub@redhat.com>
Thu, 26 Jan 2023 09:41:10 +0000 (10:41 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 26 Jan 2023 09:41:10 +0000 (10:41 +0100)
commitd427407a199a0c276cb02d6bbb64e6ecc02e590d
tree5439044aec873167a5cb2421f3698f725702a88a
parent1f6d05e9ad858b59b824f57d09400adcb2c5e4ad
openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops [PR108503]

My recent change to deduce structured binding vars earlier caused the following
invalid testcase to ICE.  The problem is that because at cp_convert_omp_range_for
when !processing_template_decl we aren't yet ready to finalize the structured bindings
(e.g. can't emit there associated code) but need to deduce types of the vars so that
we don't get errors if we parse invalid uses of those vars in inner loops of the
collapsed construct.  This is done by temporarily bumping processing_template_decl
around the call to cp_finish_decomp.  Unfortunately, as we can't finalize it yet,
the types of the vars will be deduced, but their DECL_VALUE_EXPR is not finalized
yet and if say fold_for_warn tries to constant expression evaluate them, it
recurses on DECL_VALUE_EXPR and ICEs because it sees e.g. ARRAY_REF (with NULL type)
on a VAR_DECL with class type.

The following patch works around that by temporarily hiding the DECL_VALUE_EXPRs
by clearing DECL_HAS_VALUE_EXPR_P in that case during cp_convert_omp_range_for
and arranging for cp_finish_omp_range_for to set it back before doing the
final cp_finish_decomp.

2023-01-25  Jakub Jelinek  <jakub@redhat.com>

PR c++/108503
* parser.cc (cp_convert_omp_range_for): If cp_finish_decomp has been
called in !processing_template_decl with processing_template_decl
temporarily set, clear DECL_HAS_VALUE_EXPR_P on the vars temporarily.
(cp_finish_omp_range_for): And set it back again here.

* g++.dg/gomp/pr108503.C: New test.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/gomp/pr108503.C [new file with mode: 0644]