aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKerem Kat <keremkat@gmail.com>2020-01-16 23:42:11 +0000
committerJoseph Myers <joseph@codesourcery.com>2020-01-16 23:42:11 +0000
commit852f0ae80555238c425e33f98df5c7077694bd9f (patch)
treeaf3277d077383ad1305ca29e09c7bf5621392927 /gcc
parentf5b25e15165adde1356af42e9066ab75c5b37a19 (diff)
downloadgcc-852f0ae80555238c425e33f98df5c7077694bd9f.zip
gcc-852f0ae80555238c425e33f98df5c7077694bd9f.tar.gz
gcc-852f0ae80555238c425e33f98df5c7077694bd9f.tar.bz2
Fix ICE caused by swallowing a token in c_parser_consume_token
This patch fixes ICE on invalid code, specifically files that have conflict-marker-like signs before EOF. PR c/92833 gcc/c/ * c-parser.c (c_parser_consume_token): Fix peeked token stack pop to support 4 available tokens. gcc/testsuite/ * c-c++-common/pr92833-1.c, c-c++-common/pr92833-2.c, c-c++-common/pr92833-3.c, c-c++-common/pr92833-4.c: New tests.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-parser.c6
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/c-c++-common/pr92833-1.c4
-rw-r--r--gcc/testsuite/c-c++-common/pr92833-2.c4
-rw-r--r--gcc/testsuite/c-c++-common/pr92833-3.c4
-rw-r--r--gcc/testsuite/c-c++-common/pr92833-4.c7
7 files changed, 36 insertions, 1 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index b702b39..c638756 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-16 Kerem Kat <keremkat@gmail.com>
+
+ PR c/92833
+ * c-parser.c (c_parser_consume_token): Fix peeked token stack pop
+ to support 4 available tokens.
+
2020-01-15 Joseph Myers <joseph@codesourcery.com>
PR c/93072
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index bf9e3e0..6164017 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/ChangeLog b/gcc/testsuite/ChangeLog
index 2af4d34..b2bb0217 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2020-01-16 Kerem Kat <keremkat@gmail.com>
+
+ PR c/92833
+ * c-c++-common/pr92833-1.c, c-c++-common/pr92833-2.c,
+ c-c++-common/pr92833-3.c, c-c++-common/pr92833-4.c: New tests.
+
2020-01-16 Stam Markianos-Wright <stam.markianos-wright@arm.com>
* g++.target/arm/bfloat_cpp_typecheck.C: New test.
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 0000000..ab164aa
--- /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 0000000..8347f35
--- /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 0000000..fe4f6d4
--- /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 0000000..b591ea9
--- /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