Alignment miscomputed for assignment to var-length component

Olivier Hainque hainque@act-europe.fr
Thu Mar 8 01:10:00 GMT 2001


Hello,

The patch below fixes a problem uncovered by an Ada test case involving an
assignment to a record component which type size is not constant. 

The idea is that the alignment passed to emit_block_move by expand_assignment
in such cases seems to be computed wrongly as the minimum btwn the alignment
for the source and the alignment of the record, forgetting about the offset of
the component within that record.

In the Ada test case the component was located at an odd offset within the
object and instructions performing misaligned accesses were generated.

Please let me know if anything is wrong or if additional info is required.

Kind Regards,

Olivier


        * expr.c (expand_assignment): Include component offset into
        alignment computation when assigning a varying-length object. 


Index: expr.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/expr.c,v
retrieving revision 1.295.2.1
diff -c -r1.295.2.1 expr.c
*** expr.c	2001/03/02 19:51:56	1.295.2.1
--- expr.c	2001/03/08 08:18:59
***************
*** 3710,3715 ****
--- 3710,3720 ----
  			      plus_constant (XEXP (to_rtx, 0),
  					     bitpos / BITS_PER_UNIT));
  
+ 	  /* Adjust the alignment with respect to the position of the
+ 	     targetted field.  */
+ 	  while (bitpos % (alignment * BITS_PER_UNIT) != 0)
+ 	    alignment >>= 1;
+ 
  	  emit_block_move (inner_to_rtx, from_rtx, expr_size (from),
  			   MIN (alignment, from_align));
  	  free_temp_slots ();



More information about the Gcc-patches mailing list