public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6407] openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839]
@ 2023-03-02 8:07 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-03-02 8:07 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f0ef740d54f47ff614eb02e13e8f4cb11dfbb140
commit r13-6407-gf0ef740d54f47ff614eb02e13e8f4cb11dfbb140
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Mar 2 09:02:12 2023 +0100
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.
Diff:
---
gcc/cp/parser.cc | 7 +++++--
gcc/testsuite/g++.dg/gomp/pr105839-1.C | 25 +++++++++++++++++++++++++
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 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<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 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 <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 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 <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);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-02 8:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 8:07 [gcc r13-6407] openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).