public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* c++: Fix null deref at EOF [PR96258]
@ 2020-10-16 16:25 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-10-16 16:25 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

cp_parser_declaration peeks at 1 or 2 tokens, when I changed it	not to
peek past EOF, I set the second token to NULL.	But there are paths
through the function that just look at the second token.  Fixed	by
setting that token to EOF rather than NULL in this case.

         PR c++/96258
         gcc/cp/
         * parser.c (cp_parser_declaration): Make token2 point to EOF if
         token1 was EOF.
         gcc/testsuite/
         * g++.dg/parse/pr96258.C: New.

pushing to trunk

nathan
-- 
Nathan Sidwell

[-- Attachment #2: 96258.diff --]
[-- Type: text/x-patch, Size: 1112 bytes --]

diff --git c/gcc/cp/parser.c w/gcc/cp/parser.c
index 592ce95b571..7ec7d42773c 100644
--- c/gcc/cp/parser.c
+++ w/gcc/cp/parser.c
@@ -13497,10 +13497,8 @@ cp_parser_declaration (cp_parser* parser)
 
   /* Try to figure out what kind of declaration is present.  */
   cp_token *token1 = cp_lexer_peek_token (parser->lexer);
-  cp_token *token2 = NULL;
-
-  if (token1->type != CPP_EOF)
-    token2 = cp_lexer_peek_nth_token (parser->lexer, 2);
+  cp_token *token2 = (token1->type == CPP_EOF
+		      ? token1 : cp_lexer_peek_nth_token (parser->lexer, 2));
 
   /* Get the high-water mark for the DECLARATOR_OBSTACK.  */
   void *p = obstack_alloc (&declarator_obstack, 0);
diff --git c/gcc/testsuite/g++.dg/parse/pr96258.C w/gcc/testsuite/g++.dg/parse/pr96258.C
new file mode 100644
index 00000000000..1b642e1fc38
--- /dev/null
+++ w/gcc/testsuite/g++.dg/parse/pr96258.C
@@ -0,0 +1,5 @@
+// { dg-additional-options -fopenmp }
+// { dg-require-effective-target fopenmp } 
+#pragma omp declare simd // { dg-error "not immediately followed by" }
+
+// { dg-error "-:expected unqualified-id" "" { target *-*-* } .+1 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-16 16:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 16:25 c++: Fix null deref at EOF [PR96258] Nathan Sidwell

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).