This is the mail archive of the gcc-bugs@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]

Re: Bug in edge redirection code


> 
> Okay, i found why my malloc debugger hates the following code
> (crashing on first->count -= e->count)
Hi,
the proper fix is probaby to save the values before edge gets possibly
removed.

Thu Jul 26 19:27:45 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* flow.c (try_forward_edges): Avoid accessing freed memory.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.442
diff -c -3 -p -r1.442 flow.c
*** flow.c	2001/07/25 20:51:24	1.442
--- flow.c	2001/07/26 17:27:21
*************** try_forward_edges (b)
*** 3098,3103 ****
--- 3098,3105 ----
      {
        basic_block target, first;
        int counter;
+       gcov_type edge_count;
+       int edge_frequency;
  
        next = e->succ_next;
  
*************** try_forward_edges (b)
*** 3133,3161 ****
  	}
        else if (target == first)
  	; /* We didn't do anything.  */
!       else if (redirect_edge_and_branch (e, target))
  	{
! 	  /* We successfully forwarded the edge.  Now update profile
! 	     data: for each edge we traversed in the chain, remove
! 	     the original edge's execution count.  */
! 	  do
  	    {
! 	      first->count -= e->count;
! 	      first->succ->count -= e->count;
! 	      first->frequency -= ((e->probability * b->frequency
! 				    + REG_BR_PROB_BASE / 2)
! 				   / REG_BR_PROB_BASE);
! 	      first = first->succ->dest;
! 	    }
! 	  while (first != target);
  
! 	  changed = true;
! 	}
!       else
! 	{
! 	  if (rtl_dump_file)
! 	    fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n",
! 		     b->index, e->dest->index, target->index);
  	}
      }
  
--- 3135,3169 ----
  	}
        else if (target == first)
  	; /* We didn't do anything.  */
!       else
  	{
! 	  /* Compute the values early, as redirect_edge_and_branch may
! 	     cause the edge to be removed.  */
! 	  edge_count = e->count;
! 	  edge_frequency = ((e->probability * b->frequency + REG_BR_PROB_BASE / 2)
! 			    / REG_BR_PROB_BASE);
! 	  if (redirect_edge_and_branch (e, target))
  	    {
! 	      /* We successfully forwarded the edge.  Now update profile
! 		 data: for each edge we traversed in the chain, remove
! 		 the original edge's execution count.  */
! 	      do
! 		{
! 		  first->count -= edge_count;
! 		  first->succ->count -= edge_count;
! 		  first->frequency -= edge_frequency;
! 		  first = first->succ->dest;
! 		}
! 	      while (first != target);
  
! 	      changed = true;
! 	    }
! 	  else
! 	    {
! 	      if (rtl_dump_file)
! 		fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n",
! 			 b->index, e->dest->index, target->index);
! 	    }
  	}
      }
  


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