public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
@ 2019-12-30 20:51 Kerem Kat
  2020-01-17  0:04 ` Joseph Myers
  2020-01-17 14:22 ` Jason Merrill
  0 siblings, 2 replies; 7+ messages in thread
From: Kerem Kat @ 2019-12-30 20:51 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch fixes ICE on invalid code, specifically files that have
conflict-marker-like signs before EOF.

2019-12-30  Kerem Kat  <keremkat@gmail.com>

PR c/92833
gcc/
    * c-parser.c (c_parser_consume_token): Fix peeked
    token stack pop to support 4 available tokens.

    * c-c++-common/pr92833-*.c: New tests.


diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.cindex
b3763c2e888..572805d6467 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -846,7 +846,11 @@ c_parser_consume_token (c_parser *parser)
     {
       parser->tokens[0] = parser->tokens[1];
       if (parser->tokens_avail >= 3)
- parser->tokens[1] = parser->tokens[2];
+ {
+  parser->tokens[1] = parser->tokens[2];
+  if (parser->tokens_avail >= 4)
+    parser->tokens[2] = parser->tokens[3];
+ }
     }
   parser->tokens_avail--;
 }
diff --git a/gcc/testsuite/c-c++-common/pr92833-1.c
b/gcc/testsuite/c-c++-common/pr92833-1.c
new file mode 100644
index 00000000000..ab164aae929
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr92833-1.c
@@ -0,0 +1,4 @@
+/* Six marker characters at EOF, causes conflict marker detector to peek 4
+   tokens. */
+
+/* { dg-error "expected" } */ <<<<<<
\ No newline at end of file
diff --git a/gcc/testsuite/c-c++-common/pr92833-2.c
b/gcc/testsuite/c-c++-common/pr92833-2.c
new file mode 100644
index 00000000000..8347f3542b7
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr92833-2.c
@@ -0,0 +1,4 @@
+/* Six marker characters at EOF, causes conflict marker detector to peek 4
+   tokens. */
+
+/* { dg-error "expected" } */ ======
\ No newline at end of file
diff --git a/gcc/testsuite/c-c++-common/pr92833-3.c
b/gcc/testsuite/c-c++-common/pr92833-3.c
new file mode 100644
index 00000000000..fe4f6d4c017
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr92833-3.c
@@ -0,0 +1,4 @@
+/* Six marker characters at EOF, causes conflict marker detector to peek 4
+   tokens. */
+
+/* { dg-error "expected" } */ >>>>>>
\ No newline at end of file
diff --git a/gcc/testsuite/c-c++-common/pr92833-4.c
b/gcc/testsuite/c-c++-common/pr92833-4.c
new file mode 100644
index 00000000000..b591ea9fa15
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr92833-4.c
@@ -0,0 +1,7 @@
+/* Six marker characters at EOF, causes conflict marker detector to peek 4
+   tokens. */
+
+/* { dg-message "expected" "expected" { target *-*-* } .3 } */
+>>
+>>
+>>
\ No newline at end of file

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-01-18 12:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30 20:51 [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token Kerem Kat
2020-01-17  0:04 ` Joseph Myers
2020-01-17  2:03   ` Jeff Law
2020-01-17  9:40     ` Kerem Kat
2020-01-17 14:22 ` Jason Merrill
2020-01-17 14:24   ` Jakub Jelinek
2020-01-18 13:24     ` Jakub Jelinek

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