reload.c (find_reloads_address_part): If have a CONST_INT, create...

Jim Wilson wilson@cygnus.com
Wed Nov 18 17:54:00 GMT 1998


I have checked this in to fix a reload memory corruption problem.  This
problem showed up with an irix6-x-mips-elf cross compiler while compiling
compile/920723-1.c with -mips16 -O2 -fomit-frame-pointer -finline-functions
-funroll-loops.  The symptom was that cc1 would segfault.  We'd been having
some difficult to repeat irix5 native segfaults which suddenly went away
after this patch went in, so this patch appears to be generally useful.

The sequence of events here is that reload calls eliminate_regs_in_insn,
which pushes onto the reload_obstack, creates some RTL via plus_constant,
then pops off the reload_obstack.  We then call find_reloads which ends up
calling force_const_mem, passing it RTL which is on the reload_obstack.
force_const_mem then stores away this RTL in a hash table.  After returning
from find_reloads, we call obstack_free on the reload_obstack, and now
we have pointers to freed memory in the constant pool hash table.

force_const_mem appears to have code for this case, but it is flawed.
It checks for rtl_obstack != saveable_obstack, and if so it makes a copy
of the RTL passed to it.  This does not work though, because we pop off
the reload_obstack before calling force_const_mem, so the test always
fails.

I fixed the problem by creating new rtl at the point where we call
force_const_mem.  If anyone has better ideas, I'd certainly like to hear
them.

Wed Nov 18 16:31:28 1998  Jim Wilson  <wilson@cygnus.com>

	* reload.c (find_reloads_address_part): If have a CONST_INT, create
	a new one before passing it to force_const_mem.

Index: reload.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/reload.c,v
retrieving revision 1.56
diff -p -r1.56 reload.c
*** reload.c	1998/11/18 16:32:19	1.56
--- reload.c	1998/11/19 01:51:23
*************** find_reloads_address_part (x, loc, class
*** 5517,5523 ****
        && (! LEGITIMATE_CONSTANT_P (x)
  	  || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
      {
!       rtx tem = x = force_const_mem (mode, x);
        find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
  			    opnum, type, ind_levels, 0);
      }
--- 5517,5536 ----
        && (! LEGITIMATE_CONSTANT_P (x)
  	  || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS))
      {
!       rtx tem;
! 
!       /* If this is a CONST_INT, it could have been created by a
! 	 plus_constant call in eliminate_regs, which means it may be
! 	 on the reload_obstack.  reload_obstack will be freed later, so
! 	 we can't allow such RTL to be put in the constant pool.  There
! 	 is code in force_const_mem to check for this case, but it doesn't
! 	 work because we have already popped off the reload_obstack, so
! 	 rtl_obstack == saveable_obstack is true at this point.  */
!       if (GET_CODE (x) == CONST_INT)
! 	tem = x = force_const_mem (mode, GEN_INT (INTVAL (x)));
!       else
! 	tem = x = force_const_mem (mode, x);
! 
        find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
  			    opnum, type, ind_levels, 0);
      }
*************** find_reloads_address_part (x, loc, class
*** 5527,5533 ****
  	   && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
  	       || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
      {
!       rtx tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
  
        x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
        find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),
--- 5540,5552 ----
  	   && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1))
  	       || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS))
      {
!       rtx tem;
! 
!       /* See comment above.  */
!       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
! 	tem = force_const_mem (GET_MODE (x), GEN_INT (INTVAL (XEXP (x, 1))));
!       else
! 	tem = force_const_mem (GET_MODE (x), XEXP (x, 1));
  
        x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem);
        find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0),



More information about the Gcc-patches mailing list