[committed] openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839]
Checks
Commit Message
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to
trunk.
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.
Jakub
@@ -43312,7 +43312,9 @@ cp_convert_omp_range_for (tree &this_pre
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
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);
}
}
@@ -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);
+}
@@ -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);
+}