diff mbox series

Fix PR92249

Message ID nycvar.YFH.7.76.1910281155060.5566@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR92249 | expand

Commit Message

Richard Biener Oct. 28, 2019, 10:56 a.m. UTC
This avoids segfaulting in the GIMPLE parser on invalid input.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2019-10-28  Richard Biener  <rguenther@suse.de>

	PR c/92249
	* gimple-parser.c (c_parser_parse_gimple_body): Make
	current_bb the entry block initially to easier recover
	from errors.
	(c_parser_gimple_compound_statement): Adjust.
diff mbox series

Patch

Index: gcc/c/gimple-parser.c
===================================================================
--- gcc/c/gimple-parser.c	(revision 277504)
+++ gcc/c/gimple-parser.c	(working copy)
@@ -235,6 +235,7 @@  c_parser_parse_gimple_body (c_parser *cp
       /* We have at least cdil_gimple_cfg.  */
       gimple_register_cfg_hooks ();
       init_empty_tree_cfg ();
+      parser.current_bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
       /* Initialize the bare loop structure - we are going to only
          mark headers and leave the rest to fixup.  */
       set_loops_for_fn (cfun, ggc_cleared_alloc<struct loops> ());
@@ -594,7 +595,7 @@  c_parser_gimple_compound_statement (gimp
 	      if (last_basic_block_for_fn (cfun) <= index)
 		last_basic_block_for_fn (cfun) = index + 1;
 	      n_basic_blocks_for_fn (cfun)++;
-	      if (!parser.current_bb)
+	      if (parser.current_bb->index == ENTRY_BLOCK)
 		parser.push_edge (ENTRY_BLOCK, bb->index, EDGE_FALLTHRU,
 				  profile_probability::always ());