]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Diagnose omp::directive attribute without balanced token argument [PR102413]
authorJakub Jelinek <jakub@redhat.com>
Thu, 23 Sep 2021 09:23:33 +0000 (11:23 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Thu, 23 Sep 2021 09:23:33 +0000 (11:23 +0200)
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)

gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/gomp/attrs-14.C [new file with mode: 0644]

index 98b2af83a7afc87c18be1133e95fb0b8654df2e6..f75271fcccb1b3b0130a9cb3e8aa84bc2c3cc0ab 100644 (file)
@@ -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:
index 83c51ec1bad8a617bfa64fbdf321a41286b15a1e..58d4625dbf9f5b9a8c1cdea8b84f1aea5ece4a25 100644 (file)
@@ -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);
index a31142288e58c80c767be008b0856b2ef743ec1c..c3151ad716212c42199c45a0204287f702913614 100644 (file)
@@ -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 (file)
index 0000000..959f776
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/102413
+// { dg-do compile { target c++11 } }
+
+[[omp::directive(error]];      // { dg-error "expected|declare" }