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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  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 14:22 ` Jason Merrill
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2020-01-17  0:04 UTC (permalink / raw)
  To: Kerem Kat; +Cc: gcc-patches

Thanks, patch committed.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  2020-01-17  0:04 ` Joseph Myers
@ 2020-01-17  2:03   ` Jeff Law
  2020-01-17  9:40     ` Kerem Kat
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Law @ 2020-01-17  2:03 UTC (permalink / raw)
  To: Joseph Myers, Kerem Kat; +Cc: gcc-patches

On Thu, 2020-01-16 at 23:43 +0000, Joseph Myers wrote:
> Thanks, patch committed.
Beat me to it :-)  I spun it yesterday, but didn't get around to
committing it.
jeff

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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  2020-01-17  2:03   ` Jeff Law
@ 2020-01-17  9:40     ` Kerem Kat
  0 siblings, 0 replies; 7+ messages in thread
From: Kerem Kat @ 2020-01-17  9:40 UTC (permalink / raw)
  To: law; +Cc: Joseph Myers, gcc-patches

Thank you for reviewing and committing it.

Kerem

On Fri, Jan 17, 2020 at 1:04 AM Jeff Law <law@redhat.com> wrote:

> On Thu, 2020-01-16 at 23:43 +0000, Joseph Myers wrote:
> > Thanks, patch committed.
> Beat me to it :-)  I spun it yesterday, but didn't get around to
> committing it.
> jeff
>
>

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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  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 14:22 ` Jason Merrill
  2020-01-17 14:24   ` Jakub Jelinek
  1 sibling, 1 reply; 7+ messages in thread
From: Jason Merrill @ 2020-01-17 14:22 UTC (permalink / raw)
  To: Kerem Kat, gcc-patches

On 12/30/19 3:51 PM, Kerem Kat wrote:
> +/* { dg-message "expected" "expected" { target *-*-* } .3 } */

Dejagnu doesn't like this:

ERROR: c-c++-common/pr92833-4.c  -std=c++98: expected integer but got 
".3" for " dg-message 4 "expected" "expected" { target *-*-* } .3 "

Jason

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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  2020-01-17 14:22 ` Jason Merrill
@ 2020-01-17 14:24   ` Jakub Jelinek
  2020-01-18 13:24     ` Jakub Jelinek
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2020-01-17 14:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Kerem Kat, gcc-patches

On Fri, Jan 17, 2020 at 09:07:01AM -0500, Jason Merrill wrote:
> On 12/30/19 3:51 PM, Kerem Kat wrote:
> > +/* { dg-message "expected" "expected" { target *-*-* } .3 } */
> 
> Dejagnu doesn't like this:
> 
> ERROR: c-c++-common/pr92833-4.c  -std=c++98: expected integer but got ".3"
> for " dg-message 4 "expected" "expected" { target *-*-* } .3 "

Yeah, it can handle .-3 if you want 3 lines before the one with dg-message,
or .+3 if you want 3 lines after it, or . for current line (then you can
leave that and target out), or exact line number, or some symbolic name if
earlier marked.

	Jakub

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

* Re: [PATCH] Fix ICE caused by swallowing a token in c_parser_consume_token
  2020-01-17 14:24   ` Jakub Jelinek
@ 2020-01-18 13:24     ` Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2020-01-18 13:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Kerem Kat, gcc-patches

On Fri, Jan 17, 2020 at 03:11:40PM +0100, Jakub Jelinek wrote:
> On Fri, Jan 17, 2020 at 09:07:01AM -0500, Jason Merrill wrote:
> > On 12/30/19 3:51 PM, Kerem Kat wrote:
> > > +/* { dg-message "expected" "expected" { target *-*-* } .3 } */
> > 
> > Dejagnu doesn't like this:
> > 
> > ERROR: c-c++-common/pr92833-4.c  -std=c++98: expected integer but got ".3"
> > for " dg-message 4 "expected" "expected" { target *-*-* } .3 "
> 
> Yeah, it can handle .-3 if you want 3 lines before the one with dg-message,
> or .+3 if you want 3 lines after it, or . for current line (then you can
> leave that and target out), or exact line number, or some symbolic name if
> earlier marked.

Fixed thusly, committed as obvious to trunk.

2020-01-18  Jakub Jelinek  <jakub@redhat.com>

	PR c/92833
	* c-c++-common/pr92833-4.c: Fix dg-message syntax.

--- gcc/testsuite/c-c++-common/pr92833-4.c.jj	2020-01-17 09:31:28.672194093 +0100
+++ gcc/testsuite/c-c++-common/pr92833-4.c	2020-01-18 13:51:33.718394204 +0100
@@ -1,7 +1,7 @@
 /* Six marker characters at EOF, causes conflict marker detector to peek 4
    tokens. */
 
-/* { dg-message "expected" "expected" { target *-*-* } .3 } */
+/* { dg-message "expected" "expected" { target *-*-* } .+1 } */
 >>
 >>
 >>
\ No newline at end of file


	Jakub

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