diff mbox

[gimplefe] Improve error recovery

Message ID alpine.LSU.2.11.1612200948360.5294@t29.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Dec. 20, 2016, 8:51 a.m. UTC
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.

Comments

Joseph Myers Dec. 20, 2016, 5:20 p.m. UTC | #1
On Tue, 20 Dec 2016, Richard Biener wrote:

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

I'm fine with that.
diff mbox

Patch

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;