public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-6407] openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839]
Date: Thu, 2 Mar 2023 08:07:08 +0000 (GMT) [thread overview]
Message-ID: <20230302080708.6CD153858D33@sourceware.org> (raw)
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);
+}
reply other threads:[~2023-03-02 8:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230302080708.6CD153858D33@sourceware.org \
--to=jakub@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).