From 852f0ae80555238c425e33f98df5c7077694bd9f Mon Sep 17 00:00:00 2001 From: Kerem Kat Date: Thu, 16 Jan 2020 23:42:11 +0000 Subject: [PATCH] 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. --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-parser.c | 6 +++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/c-c++-common/pr92833-1.c | 4 ++++ gcc/testsuite/c-c++-common/pr92833-2.c | 4 ++++ gcc/testsuite/c-c++-common/pr92833-3.c | 4 ++++ gcc/testsuite/c-c++-common/pr92833-4.c | 7 +++++++ 7 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/pr92833-1.c create mode 100644 gcc/testsuite/c-c++-common/pr92833-2.c create mode 100644 gcc/testsuite/c-c++-common/pr92833-3.c create mode 100644 gcc/testsuite/c-c++-common/pr92833-4.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b702b39b95a..c6387560b40 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2020-01-16 Kerem Kat + + 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 PR c/93072 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index bf9e3e05d3e..6164017de02 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 2af4d34d167..b2bb021799a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-01-16 Kerem Kat + + 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 * 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 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 -- 2.30.2