fix memory overflow in connect_infinite_loops_to_exit

Jan Hubicka jh@suse.cz
Thu Nov 15 09:42:00 GMT 2001


Hi,
the connect_infinite_loops_to_exit overwrites unallocated memory, as it
allocates stack if size n_basic_blocks, but may push each block to it
multiple times.

This patch changes the algorithm to set visited block once the block appears on
the stack so we push maximally n_basic_blocks blocks.

Installed to the cfg-branch, bootstrapped, regtested, OK for mainilne?
(the code is not used, so I did only first stage of bootstrap).

Honza

Mon Nov 26 11:43:47 CET 2001  Jan Hubicka  <jh@suse.cz>
	* cfganal.c (flow_dfs_compute_reverse_add_bb): set visited bit.
	(flow_dfs_compute_reverse_execute): Add only unvisited blocks.
Index: cfganal.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cfganal.c,v
retrieving revision 1.6
diff -c -3 -p -r1.6 cfganal.c
*** cfganal.c	2001/11/11 11:25:13	1.6
--- cfganal.c	2001/11/26 10:43:41
*************** flow_dfs_compute_reverse_add_bb (data, b
*** 980,985 ****
--- 980,986 ----
       basic_block bb;
  {
    data->stack[data->sp++] = bb;
+   SET_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1));
    return;
  }
  
*************** flow_dfs_compute_reverse_execute (data)
*** 999,1014 ****
    while (data->sp > 0)
      {
        bb = data->stack[--data->sp];
! 
!       /* Mark that we have visited this node.  */
!       if (!TEST_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1)))
! 	{
! 	  SET_BIT (data->visited_blocks, bb->index - (INVALID_BLOCK + 1));
! 
! 	  /* Perform depth-first search on adjacent vertices.  */
! 	  for (e = bb->pred; e; e = e->pred_next)
! 	    flow_dfs_compute_reverse_add_bb (data, e->src);
! 	}
      }
  
    /* Determine if there are unvisited basic blocks.  */
--- 1000,1009 ----
    while (data->sp > 0)
      {
        bb = data->stack[--data->sp];
!       /* Perform depth-first search on adjacent vertices.  */
!       for (e = bb->pred; e; e = e->pred_next)
! 	if (!TEST_BIT (data->visited_blocks, e->src->index - (INVALID_BLOCK + 1)))
! 	  flow_dfs_compute_reverse_add_bb (data, e->src);
      }
  
    /* Determine if there are unvisited basic blocks.  */



More information about the Gcc-patches mailing list