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 r12-3831] openmp: Diagnose omp::directive attribute without balanced token argument [PR102413] Date: Thu, 23 Sep 2021 08:11:11 +0000 (GMT) [thread overview] Message-ID: <20210923081111.A56793858D39@sourceware.org> (raw) https://gcc.gnu.org/g:0d39eb28fd2ab00306bd7c0a87b6c0ed615b5d12 commit r12-3831-g0d39eb28fd2ab00306bd7c0a87b6c0ed615b5d12 Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Sep 23 10:07:49 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. Diff: --- gcc/cp/parser.c | 11 ++++++++++- gcc/testsuite/g++.dg/gomp/attrs-14.C | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 26d925c15c5..052fa25ebda 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28628,7 +28628,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/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" }
reply other threads:[~2021-09-23 8:11 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=20210923081111.A56793858D39@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: linkBe 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).