diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-03-02 09:02:12 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-03-02 09:06:58 +0100 |
commit | f0ef740d54f47ff614eb02e13e8f4cb11dfbb140 (patch) | |
tree | 910ce6a610ee4dea1bd8f024efcd06138941305e /gcc | |
parent | a2926653ebbc88e8bba335563fa86b44651598d6 (diff) | |
download | gcc-f0ef740d54f47ff614eb02e13e8f4cb11dfbb140.zip gcc-f0ef740d54f47ff614eb02e13e8f4cb11dfbb140.tar.gz gcc-f0ef740d54f47ff614eb02e13e8f4cb11dfbb140.tar.bz2 |
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 <jakub@redhat.com>
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/parser.cc | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/gomp/pr105839-1.C | 25 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/gomp/pr105839-2.C | 24 |
3 files changed, 54 insertions, 2 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 1a124f5..3d6b8f2 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<tree, va_gc> *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 0000000..64fb6a3 --- /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 <typename T> +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 0000000..fdb7595 --- /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 <typename T> +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); +} |