Fix for 20011128-1.c

law@redhat.com law@redhat.com
Sun Nov 18 13:10:00 GMT 2001


When we clear residual space in an array after a string->array copy
operation we can generate unaligned memory references?

Why?  Because the alignment of the residual space may not be the same
as the alignment of the destination array.  Consider if the array had
64bit alignment, started at byte address 0x100 and we copied a 10 character
string into it.  The memory we want to clear starts at 0x10b which is
only byte aligned.  If we fail to set the alignment properly on the MEM
for the residual, clear_storage will generate unaligned stores, thus
causing segfaults.

While it would be possible to determine the alignment of the residual space,
it didn't seem worth the effort, so I just set it to have byte alignment.

Bootstrapped and tested on hppa2.0-hp-hpux11.00.

	* expr.c (store_expr): When copying a string constant into an
	array, reset the known alignment of the MEM for the section to
	be cleared to BITS_PER_UNIT.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.c,v
retrieving revision 1.386
diff -c -3 -p -r1.386 expr.c
*** expr.c	2001/11/27 14:31:14	1.386
--- expr.c	2001/11/28 22:25:16
*************** store_expr (exp, target, want_value)
*** 4293,4298 ****
--- 4293,4304 ----
  
  		  MEM_COPY_ATTRIBUTES (dest, target);
  
+ 		  /* The residual likely does not have the same alignment
+ 		     as the original target.  While we could compute the
+ 		     alignment of the residual, it hardely seems worth
+ 		     the effort.  */
+ 		  set_mem_align (dest, BITS_PER_UNIT);
+ 
  		  /* Be sure we can write on ADDR.  */
  		  in_check_memory_usage = 1;
  		  if (current_function_check_memory_usage)









More information about the Gcc-patches mailing list