This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

[PATCH] Tiny fix to output_constant


Hi,

Through the Unchecked Conversion mechanism, constants can be casted to pretty 
much anything in Ada.  When this happens for the initializer of a static 
variable, the constant reaches output_constant with 'size' set to the size 
of the casted to type.

The 'size' argument is then passed down to assemble_integer, which pads with 
0 if the actual size of the constant is smaller.  Now output_constant is 
wired to pad with 0 too:

  if (size > thissize)
    assemble_zeros (size - thissize);

so we end up with double padding.


The proposed fix is to use 'MIN (size, thissisze)' instead of 'size' in:

    case CHAR_TYPE:
    case BOOLEAN_TYPE:
    case INTEGER_TYPE:
    case ENUMERAL_TYPE:
    case POINTER_TYPE:
    case REFERENCE_TYPE:
    case OFFSET_TYPE:
      if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
					   EXPAND_INITIALIZER),
			      size, align, 0))
	error ("initializer for integer value is too complicated");
      break;

This doesn't change anything if 'size' is smaller (obviously) and avoids 
double-padding if 'thissize' is smaller.

Boostrapped/regtested on i586-redhat-linux-gnu (mainline and 3.4 branch), 
sparc-sun-solaris2.8 and sparc64-sun-solaris2.9 (3.4 branch).  OK for 
mainline?


2004-05-25  Eric Botcazou  <ebotcazou@act-europe.fr>

        * varasm.c (output_constant) <INTEGER_TYPE>: Pass the minimum
        of the two sizes to assemble_integer.


-- 
Eric Botcazou
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.426
diff -u -p -r1.426 varasm.c
--- varasm.c	19 May 2004 02:11:41 -0000	1.426
+++ varasm.c	25 May 2004 05:47:35 -0000
@@ -3576,7 +3576,7 @@ output_constant (tree exp, unsigned HOST
     case OFFSET_TYPE:
       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
 					   EXPAND_INITIALIZER),
-			      size, align, 0))
+			      MIN (size, thissize), align, 0))
 	error ("initializer for integer value is too complicated");
       break;
 

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