public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][gimplefe] Improve error recovery
@ 2016-12-20  8:57 Richard Biener
  2016-12-20 17:26 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2016-12-20  8:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph S. Myers


Just noticed a few issues when feeding the GIMPLE FE random -gimple
dumps.  On errors not skipping to expected tokens leads to a load
of strange followup parsing errors and worse, to endless parsing
attempts in one case.

Fixed with the following.

Bootstrap / regtest running together with the pass manager change
posted in the other thread.

I consider gimple-parser.c changes like this "middle-end", Joseph,
are you fine with that?

Richard.

2016-12-20  Richard Biener  <rguenther@suse.de>

	c/
	* gimple-parser.c (c_parser_gimple_compound_statement): Improve
	error recovery.
	(c_parser_gimple_statement): Only build assigns for non-error
	stmts.
	(c_parser_gimple_postfix_expression_after): Improve error recovery.

Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c	(revision 243738)
+++ gcc/c/gimple-parser.c	(working copy)
@@ -215,7 +215,7 @@ c_parser_gimple_compound_statement (c_pa
 expr_stmt:
 	  c_parser_gimple_statement (parser, seq);
 	  if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>"))
-	    return return_p;
+	    c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);
 	}
     }
   c_parser_consume_token (parser);
@@ -327,9 +327,12 @@ c_parser_gimple_statement (c_parser *par
     case CPP_NOT:
     case CPP_MULT: /* pointer deref */
       rhs = c_parser_gimple_unary_expression (parser);
-      assign = gimple_build_assign (lhs.value, rhs.value);
-      gimple_set_location (assign, loc);
-      gimple_seq_add_stmt (seq, assign);
+      if (rhs.value != error_mark_node)
+	{
+	  assign = gimple_build_assign (lhs.value, rhs.value);
+	  gimple_set_location (assign, loc);
+	  gimple_seq_add_stmt (seq, assign);
+	}
       return;
 
     default:;
@@ -385,10 +388,13 @@ c_parser_gimple_statement (c_parser *par
       && lookup_name (c_parser_peek_token (parser)->value))
     {
       rhs = c_parser_gimple_unary_expression (parser);
-      gimple *call = gimple_build_call_from_tree (rhs.value);
-      gimple_call_set_lhs (call, lhs.value);
-      gimple_seq_add_stmt (seq, call);
-      gimple_set_location (call, loc);
+      if (rhs.value != error_mark_node)
+	{
+	  gimple *call = gimple_build_call_from_tree (rhs.value);
+	  gimple_call_set_lhs (call, lhs.value);
+	  gimple_seq_add_stmt (seq, call);
+	  gimple_set_location (call, loc);
+	}
       return;
     }
 
@@ -802,7 +808,10 @@ c_parser_gimple_postfix_expression_after
 	    tree idx = c_parser_gimple_unary_expression (parser).value;
 
 	    if (! c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>"))
-	      break;
+	      {
+		c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL);
+		break;
+	      }
 
 	    start = expr.get_start ();
 	    finish = c_parser_tokens_buf (parser, 0)->location;

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

end of thread, other threads:[~2016-12-20 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20  8:57 [PATCH][gimplefe] Improve error recovery Richard Biener
2016-12-20 17:26 ` Joseph Myers

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