From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86951 invoked by alias); 18 Nov 2016 22:46:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 86891 invoked by uid 89); 18 Nov 2016 22:46:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Nov 2016 22:46:36 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC73A3F730; Fri, 18 Nov 2016 22:46:34 +0000 (UTC) Received: from c64.redhat.com (vpn-226-30.phx2.redhat.com [10.3.226.30]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAIMkXoe030662; Fri, 18 Nov 2016 17:46:34 -0500 From: David Malcolm To: Joseph Myers Cc: Richard Biener , Jan Hubicka , GCC Patches , David Malcolm Subject: [PATCH] Handle EOF in c_parser_parse_rtl_body Date: Fri, 18 Nov 2016 22:46:00 -0000 Message-Id: <1479511129-56457-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: References: X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg02010.txt.bz2 On Fri, 2016-11-18 at 22:13 +0000, Joseph Myers wrote: > On Fri, 18 Nov 2016, David Malcolm wrote: > > > + /* Consume all tokens, up to the closing brace, handling > > + matching pairs of braces in the rtl dump. */ > > + int num_open_braces = 1; > > + while (1) > > + { > > + switch (c_parser_peek_token (parser)->type) > > + { > > + case CPP_OPEN_BRACE: > > + num_open_braces++; > > + break; > > + case CPP_CLOSE_BRACE: > > + if (--num_open_braces == 0) > > + goto found_closing_brace; > > + break; > > + default: > > + break; > > + } > > + c_parser_consume_token (parser); > > + } > > What if you have an EOF without the close brace being found? I'd > expect > you to hit the > > gcc_assert (parser->tokens[0].type != CPP_EOF); > > in c_parser_consume_token. Oops; thanks. Here's a patch on top of v5 that (I hope) addresses that. gcc/c/ChangeLog: * c-parser.c (c_parser_parse_rtl_body): Handle CPP_EOF. gcc/testsuite/ChangeLog: * gcc.dg/rtl/truncated-rtl-file.c: New test case. --- gcc/c/c-parser.c | 4 ++++ gcc/testsuite/gcc.dg/rtl/truncated-rtl-file.c | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/rtl/truncated-rtl-file.c diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index d645d29..fef882a 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -18326,6 +18326,10 @@ c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass) if (--num_open_braces == 0) goto found_closing_brace; break; + case CPP_EOF: + error_at (start_loc, "no closing brace"); + free (start_with_pass); + return; default: break; } diff --git a/gcc/testsuite/gcc.dg/rtl/truncated-rtl-file.c b/gcc/testsuite/gcc.dg/rtl/truncated-rtl-file.c new file mode 100644 index 0000000..4dd8214 --- /dev/null +++ b/gcc/testsuite/gcc.dg/rtl/truncated-rtl-file.c @@ -0,0 +1,2 @@ +void __RTL test (void) +{ /* { dg-error "no closing brace" } */ -- 1.8.5.3