[RFC PATCH] Fix middle-end/6963

Ulrich Weigand weigand@immd1.informatik.uni-erlangen.de
Thu Jun 20 15:53:00 GMT 2002


Hello,

this patch is an attempt to fix middle-end/6963, the problem 
described in 
   http://gcc.gnu.org/ml/gcc/2002-06/msg00554.html

As the problem appears to be caused by multiple user of the
same temp stack slot clobbering each others's MEM attributes
because assign_stack_temp_for_type returns the same MEM rtx
for multiple re-uses of a stack slot, I'd thought to fix this
by having assign_stack_temp_for_type instead create a new rtx
every time a stack slot is reused.

This fixes the test case that was failing on s390x, and it
survives a bootstrap/regtest on i686-pc-unknown-linux (I'll
test s390/s390x tomorrow).  (The patch is against the 3.1
branch, and the test was run there.)

However, I'm not sure if the fix is correct, as I don't 
understand why the rtx was shared in the first place (I also
do not understand the stack_slot_list business).  Is this
just a matter of efficiency, or something else?

I'd appreciate any help to understand this problem.

Bye,
Ulrich


ChangeLog:

	* function.c (assign_stack_temp_for_type): Do not return
	the same MEM rtx for multiple uses of a stack slot.


Index: gcc/function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.347.2.9
diff -c -p -r1.347.2.9 function.c
*** gcc/function.c	23 Apr 2002 08:11:19 -0000	1.347.2.9
--- gcc/function.c	20 Jun 2002 21:33:16 -0000
*************** assign_stack_temp_for_type (mode, size, 
*** 666,671 ****
--- 666,672 ----
  {
    unsigned int align;
    struct temp_slot *p, *best_p = 0;
+   rtx slot;
  
    /* If SIZE is -1 it means that somebody tried to allocate a temporary
       of a variable size.  */
*************** assign_stack_temp_for_type (mode, size, 
*** 811,839 ****
        p->keep = keep;
      }
  
!   /* We may be reusing an old slot, so clear any MEM flags that may have been
!      set from before.  */
!   RTX_UNCHANGING_P (p->slot) = 0;
!   MEM_IN_STRUCT_P (p->slot) = 0;
!   MEM_SCALAR_P (p->slot) = 0;
!   MEM_VOLATILE_P (p->slot) = 0;
!   set_mem_alias_set (p->slot, 0);
  
    /* If we know the alias set for the memory that will be used, use
       it.  If there's no TYPE, then we don't know anything about the
       alias set for the memory.  */
!   set_mem_alias_set (p->slot, type ? get_alias_set (type) : 0);
!   set_mem_align (p->slot, align);
  
    /* If a type is specified, set the relevant flags.  */
    if (type != 0)
      {
!       RTX_UNCHANGING_P (p->slot) = TYPE_READONLY (type);
!       MEM_VOLATILE_P (p->slot) = TYPE_VOLATILE (type);
!       MEM_SET_IN_STRUCT_P (p->slot, AGGREGATE_TYPE_P (type));
      }
  
!   return p->slot;
  }
  
  /* Allocate a temporary stack slot and record it for possible later
--- 812,837 ----
        p->keep = keep;
      }
  
! 
!   /* Create a new MEM rtx to avoid clobbering MEM flags of old slots.  */
!   slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
!   stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
  
    /* If we know the alias set for the memory that will be used, use
       it.  If there's no TYPE, then we don't know anything about the
       alias set for the memory.  */
!   set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
!   set_mem_align (slot, align);
  
    /* If a type is specified, set the relevant flags.  */
    if (type != 0)
      {
!       RTX_UNCHANGING_P (slot) = TYPE_READONLY (type);
!       MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
!       MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
      }
  
!   return slot;
  }
  
  /* Allocate a temporary stack slot and record it for possible later
-- 
  Dr. Ulrich Weigand
  weigand@informatik.uni-erlangen.de



More information about the Gcc-patches mailing list