From: Jakub Jelinek Date: Thu, 2 Mar 2023 08:02:12 +0000 (+0100) Subject: openmp: Fix up error recovery for invalid structured bindings in OpenMP range for... X-Git-Tag: upstream/13.1.0~837 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0ef740d54f47ff614eb02e13e8f4cb11dfbb140;p=platform%2Fupstream%2Fgcc.git openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839] The PR108503 temporary DECL_HAS_VALUE_EXPR_P clearing code can ICE during recovery, because cp_finish_decomp when it detects errors and reports them clears DECL_HAS_VALUE_EXPR_P, clears DECL_VALUE_EXPR and sets TREE_TYPE of the structured binding vars to error_mark_node. The PR108503 code had an assertion that DECL_HAS_VALUE_EXPR_P is set so that it can clear it and restore later. The following patch allows DECL_HAS_VALUE_EXPR_P to be unset if type is error_mark_node and doesn't set it again in that case. 2023-03-02 Jakub Jelinek PR c++/105839 * parser.cc (cp_convert_omp_range_for): Allow in assert decomp_first_name without DECL_HAS_VALUE_EXPR_P if it has error_mark_node type. (cp_finish_omp_range_for): Don't set DECL_HAS_VALUE_EXPR_P back on decls which have error_mark_node type. * g++.dg/gomp/pr105839-1.C: New test. * g++.dg/gomp/pr105839-2.C: New test. --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 1a124f5395e..3d6b8f252a3 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -43312,7 +43312,9 @@ cp_convert_omp_range_for (tree &this_pre_body, vec *for_block, name but the DECL_VALUE_EXPR will be dependent. Hide those from folding of other loop initializers e.g. for warning purposes until cp_finish_omp_range_for. */ - gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (decomp_first_name)); + gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (decomp_first_name) + || (TREE_TYPE (decomp_first_name) + == error_mark_node)); DECL_HAS_VALUE_EXPR_P (decomp_first_name) = 0; } TREE_VEC_ELT (v, i + 3) = decomp_first_name; @@ -43345,7 +43347,8 @@ cp_finish_omp_range_for (tree orig, tree begin) tree d = decomp_first_name; for (unsigned i = 0; i < decomp_cnt; i++) { - DECL_HAS_VALUE_EXPR_P (d) = 1; + if (TREE_TYPE (d) != error_mark_node) + DECL_HAS_VALUE_EXPR_P (d) = 1; d = DECL_CHAIN (d); } } diff --git a/gcc/testsuite/g++.dg/gomp/pr105839-1.C b/gcc/testsuite/g++.dg/gomp/pr105839-1.C new file mode 100644 index 00000000000..64fb6a39563 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr105839-1.C @@ -0,0 +1,25 @@ +// PR c++/105839 +// { dg-do compile { target c++11 } } +// { dg-options "-fopenmp" } + +template +void +foo (const T &x) +{ + [&] (auto &&y) // { dg-error "use of 'auto' in lambda parameter declaration only available with" "" { target c++11_only } } + { + #pragma omp parallel for + for (auto &&[v1, v2] : x) // { dg-error "cannot decompose non-array non-class type 'const int'" } + ; // { dg-error "invalid type for iteration variable" "" { target c++14 } .-1 } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-2 } + } ([]{}); // { dg-error "no match for call to" "" { target c++11_only } } + // { dg-error "invalid user-defined conversion from" "" { target c++11_only } .-1 } + // { dg-error "invalid conversion from" "" { target c++11_only } .-2 } +} + +void +bar () +{ + int a[10]; + foo (a); +} diff --git a/gcc/testsuite/g++.dg/gomp/pr105839-2.C b/gcc/testsuite/g++.dg/gomp/pr105839-2.C new file mode 100644 index 00000000000..fdb75958c5f --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/pr105839-2.C @@ -0,0 +1,24 @@ +// PR c++/105839 +// { dg-do compile { target c++14 } } +// { dg-options "-fopenmp" } + +template +void +foo (const T &x) +{ + [&] (auto &&y) + { + #pragma omp parallel for + for (auto &&[v1, v2] : x) // { dg-warning "structured bindings only available with" "" { target c++14_down } } + ; + } ([]{}); +} + +struct A { int a, b; }; + +void +bar () +{ + A a[10]; + foo (a); +}