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.
This commit is contained in:
Kerem Kat 2020-01-16 23:42:11 +00:00 committed by Joseph Myers
parent f5b25e1516
commit 852f0ae805
7 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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--;
}

View File

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

View File

@ -0,0 +1,4 @@
/* Six marker characters at EOF, causes conflict marker detector to peek 4
tokens. */
/* { dg-error "expected" } */ <<<<<<

View File

@ -0,0 +1,4 @@
/* Six marker characters at EOF, causes conflict marker detector to peek 4
tokens. */
/* { dg-error "expected" } */ ======

View File

@ -0,0 +1,4 @@
/* Six marker characters at EOF, causes conflict marker detector to peek 4
tokens. */
/* { dg-error "expected" } */ >>>>>>

View File

@ -0,0 +1,7 @@
/* Six marker characters at EOF, causes conflict marker detector to peek 4
tokens. */
/* { dg-message "expected" "expected" { target *-*-* } .3 } */
>>
>>
>>