[gcc/devel/omp/gcc-11] openmp: Diagnose omp::directive attribute without balanced token argument [PR102413]
Tobias Burnus
burnus@gcc.gnu.org
Thu Sep 23 09:34:04 GMT 2021
https://gcc.gnu.org/g:4b5cf43626c82ebf3888bdc6b395ab2ba49c1b2a
commit 4b5cf43626c82ebf3888bdc6b395ab2ba49c1b2a
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Sep 23 11:23:33 2021 +0200
openmp: Diagnose omp::directive attribute without balanced token argument [PR102413]
If omp::directive attribute argument starting with the opening ( is not a balanced
token sequence, then cp_parser_skip_balanced_tokens (parser, 1) returns 1,
but the code was subtracting 2 from it and iterating until it was 0, so for the
non-balanced case it iterated from (size_t) -1 down to 0.
The following patch just diagnoses that as an error.
2021-09-23 Jakub Jelinek <jakub@redhat.com>
PR c++/102413
* parser.c (cp_parser_omp_directive_args): Diagnose if omp::directive
is not followed by a balanced token sequence starting with open paren.
* g++.dg/gomp/attrs-14.C: New test.
(cherry picked from commit 0d39eb28fd2ab00306bd7c0a87b6c0ed615b5d12)
Diff:
---
gcc/cp/ChangeLog.omp | 8 ++++++++
gcc/cp/parser.c | 11 ++++++++++-
gcc/testsuite/ChangeLog.omp | 7 +++++++
gcc/testsuite/g++.dg/gomp/attrs-14.C | 4 ++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp
index 98b2af83a7a..f75271fcccb 100644
--- a/gcc/cp/ChangeLog.omp
+++ b/gcc/cp/ChangeLog.omp
@@ -1,3 +1,11 @@
+2021-09-23 Tobias Burnus <tobias@codesourcery.com>
+
+ 2021-09-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/102413
+ * parser.c (cp_parser_omp_directive_args): Diagnose if omp::directive
+ is not followed by a balanced token sequence starting with open paren.
+
2021-09-23 Tobias Burnus <tobias@codesourcery.com>
Backported from master:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 83c51ec1bad..58d4625dbf9 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -28379,7 +28379,16 @@ cp_parser_omp_directive_args (cp_parser *parser, tree attribute)
TREE_VALUE (attribute) = NULL_TREE;
return;
}
- for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 2; n; --n)
+ size_t n = cp_parser_skip_balanced_tokens (parser, 1);
+ if (n == 1)
+ {
+ cp_lexer_consume_token (parser->lexer);
+ error_at (first->location, "expected attribute argument as balanced "
+ "token sequence");
+ TREE_VALUE (attribute) = NULL_TREE;
+ return;
+ }
+ for (n = n - 2; n; --n)
cp_lexer_consume_token (parser->lexer);
cp_token *last = cp_lexer_peek_token (parser->lexer);
cp_lexer_consume_token (parser->lexer);
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index a31142288e5..c3151ad7162 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-09-23 Tobias Burnus <tobias@codesourcery.com>
+
+ 2021-09-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/102413
+ * g++.dg/gomp/attrs-14.C: New test.
+
2021-09-23 Tobias Burnus <tobias@codesourcery.com>
Backported from master:
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-14.C b/gcc/testsuite/g++.dg/gomp/attrs-14.C
new file mode 100644
index 00000000000..959f7764cf1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/attrs-14.C
@@ -0,0 +1,4 @@
+// PR c++/102413
+// { dg-do compile { target c++11 } }
+
+[[omp::directive(error]]; // { dg-error "expected|declare" }
More information about the Gcc-cvs
mailing list