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]

[tree-profiling] Fix a latent cfgexpand.c bug


Hi,

We shouldn't call remove_edge and expect it to be not free-ed.
I just commited this after bootstrapping with the ggc_free
calls in cfg.c uncommented.

Gr.
Steven

2004-05-25  Steven Bosscher  <stevenb@suse.de>

        * cfgexpand.c (expand_block): Expect an edge that has been removed
        to point to free()ed memory.

Index: cfgexpand.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cfgexpand.c,v
retrieving revision 1.1.2.12
diff -c -3 -p -r1.1.2.12 cfgexpand.c
*** cfgexpand.c	29 Apr 2004 07:27:33 -0000	1.1.2.12
--- cfgexpand.c	25 May 2004 23:34:07 -0000
*************** expand_block (basic_block bb, FILE * dum
*** 116,123 ****
  
    NOTE_BASIC_BLOCK (note) = bb;
  
!   for (e = bb->succ; e; e = e->succ_next)
      {
        /* Clear EDGE_EXECUTABLE.  This flag is never used in the backend.  */
        e->flags &= ~EDGE_EXECUTABLE;
  
--- 116,126 ----
  
    NOTE_BASIC_BLOCK (note) = bb;
  
!   e = bb->succ;
!   while (e)
      {
+       edge next = e->succ_next;
+ 
        /* Clear EDGE_EXECUTABLE.  This flag is never used in the backend.  */
        e->flags &= ~EDGE_EXECUTABLE;
  
*************** expand_block (basic_block bb, FILE * dum
*** 126,131 ****
--- 129,136 ----
           rediscover them.  In the future we should get this fixed properly.  */
        if (e->flags & EDGE_ABNORMAL)
  	remove_edge (e);
+ 
+       e = next;
      }
  
    for (; !bsi_end_p (bsi); bsi_next (&bsi))
*************** expand_block (basic_block bb, FILE * dum
*** 230,251 ****
  		  gcov_type count = 0;
  
  		  do_pending_stack_adjust ();
! 		  for (e = bb->succ; e; e = e->succ_next)
! 		    if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
! 		      {
! 			if (e->dest != EXIT_BLOCK_PTR)
! 			  {
! 			    e->dest->count -= e->count;
! 			    e->dest->frequency -= EDGE_FREQUENCY (e);
! 			    if (e->dest->count < 0)
! 			      e->dest->count = 0;
! 			    if (e->dest->frequency < 0)
! 			      e->dest->frequency = 0;
! 			  }
! 			count += e->count;
! 			probability += e->probability;
! 			remove_edge (e);
! 		      }
  
  		  /* This is somewhat ugly:  the call_expr expander often emits instructions
  		     after the sibcall (to perform the function return).  These confuse the 
--- 235,263 ----
  		  gcov_type count = 0;
  
  		  do_pending_stack_adjust ();
! 		  e = bb->succ;
! 		  while (e)
! 		    {
! 		      edge next = e->succ_next;
! 
! 		      if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
! 			{
! 			  if (e->dest != EXIT_BLOCK_PTR)
! 			    {
! 			      e->dest->count -= e->count;
! 			      e->dest->frequency -= EDGE_FREQUENCY (e);
! 			      if (e->dest->count < 0)
! 			        e->dest->count = 0;
! 			      if (e->dest->frequency < 0)
! 			        e->dest->frequency = 0;
! 			    }
! 			  count += e->count;
! 			  probability += e->probability;
! 			  remove_edge (e);
! 			}
! 
! 		      e = next;
! 		    }
  
  		  /* This is somewhat ugly:  the call_expr expander often emits instructions
  		     after the sibcall (to perform the function return).  These confuse the 


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