This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New C parser, version 8


Here is a new parser patch fixing an infinite loop in error recovery noted 
on IRC.  Incremental patch, and testcase for the bug (which has been added 
to mainline), below; full patch attached.  Bootstrapped with no 
regressions on x86_64-unknown-linux-gnu.  I had previously audited for 
infinite loops in error recovery but then I was looking specifically for 
such loops at EOF and not the sort of case found here.

2005-02-09  Joseph S. Myers  <joseph@codesourcery.com>

	* c-parser.c: New file.
	* c-parse.in: Remove.
	* Makefile.in (c-parse.o-warn, c-parse.o, c-parse.c, c-parse.y):
	Remove.
	(c-parser.o): Add dependencies.
	(C_AND_OBJC_OBJC, C_OBJS, gcc.srcextra, GTFILES, distclean,
	maintainer-clean, TAGS): Update.
	* c-config-lang.in (gtfiles): Update.
	* gengtype-lex.l: Don't handle "@@".
	* stub-objc.c (objc_get_class_ivars, objc_build_throw_stmt,
	objc_build_synchronized, objc_begin_try_stmt,
	objc_begin_catch_clause, objc_finish_catch_clause,
	objc_build_finally_clause, objc_finish_try_stmt): New.
	* c-tree.h (struct c_declspecs): Add declspecs_seen_p and
	type_seen_p.
	(c_parse_init): Update comment.
	* c-decl.c (c_init_decl_processing): Update comment.
	(build_null_declspecs, declspecs_add_qual, declspecs_add_type,
	declspecs_add_scspec, declspecs_add_attrs): Initialize and update
	new c_declspecs members.

objc:
2005-02-09  Joseph S. Myers  <joseph@codesourcery.com>

	* Make-lang.in (objc/objc-parse.o-warn, objc/objc-parse.o,
	objc/objc-parse.c, objc/objc-parse.y): Remove
	(OBJC_OBJS, objc.srcextra, objc.tags, objc.mostlyclean,
	objc.distclean, objc.maintainer-clean): Update for new parser.
	* config-lang.in (gtfiles): Update for new parser.

testsuite:
2005-02-09  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/cpp/separate-1.c, gcc.dg/noncompile/971104-1.c,
	gcc.dg/noncompile/990416-1.c: Adjust expected messages for new
	parser.

--- c-parser.c-v7	2005-02-02 12:18:19.000000000 +0000
+++ c-parser.c-v8	2005-02-09 00:47:14.000000000 +0000
@@ -3536,6 +3536,15 @@ c_parser_statement_after_labels (c_parse
     case CPP_SEMICOLON:
       c_parser_consume_token (parser);
       break;
+    case CPP_CLOSE_PAREN:
+    case CPP_CLOSE_SQUARE:
+      /* Avoid infinite loop in error recovery:
+	 c_parser_skip_until_found stops at a closing nesting
+	 delimiter without consuming it, but here we need to consume
+	 it to proceed further.  */
+      c_parser_error (parser, "expected statement");
+      c_parser_consume_token (parser);
+      break;
     default:
     expr_stmt:
       stmt = c_finish_expr_stmt (c_parser_expression (parser).value);

/* Test for infinite loop in parser error recovery.  From Serge
   Belyshev <ssb> on IRC.  */
/* { dg-do compile } */
/* { dg-options "" } */
int f() { return 1); } /* { dg-error "parse|syntax|expected" } */

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

Attachment: c-parser-patch-version-8.gz
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]