This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] 32 bit non-eabi mips va_arg
- To: gcc-patches at gcc dot gnu dot org
- Subject: [patch] 32 bit non-eabi mips va_arg
- From: Clinton Popetz <cpopetz at cpopetz dot com>
- Date: Fri, 14 Jan 2000 10:56:02 -0600
The original 32 bit non-eabi mips va_arg did this:
#ifdef __MIPSEB__
/* For big-endian machines. */
#define va_arg(__AP, __type) \
((__AP = (char *) ((__alignof__ (__type) > 4 \
? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
: ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
+ __va_rounded_size (__type))), \
*(__type *) (void *) (__AP - __va_rounded_size (__type)))
#else
/* For little-endian machines. */
#define va_arg(__AP, __type) \
((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \
? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
: ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
+ __va_rounded_size(__type))))[-1]
#endif
This is the reverse of the padding convention in std_expand_builtin_va_arg, and
so passing small varargs is currrently broken for 32bit non-eabi mips. Rather
than copy all of that code into mips_va_arg, I'm hoping the following patch is
acceptable. I think it would also make sense to make std_expand_builtin_va_arg
use FUNCTION_ARG_PADDING. But there are a few ports (rs6000 is one) that
define FUNCTION_ARG_PADDING and also use std_expand_builtin_va_arg, so I
presume padding for varargs should remain orthogonal to padding for normal
arguments.
-Clint
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/builtins.c,v
retrieving revision 1.25
diff -c -2 -p -r1.25 builtins.c
*** builtins.c 2000/01/11 23:27:40 1.25
--- builtins.c 2000/01/14 16:00:01
*************** Boston, MA 02111-1307, USA. */
*** 52,55 ****
--- 52,59 ----
#endif
+ #ifndef PAD_VARARGS_DOWN
+ #define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN
+ #endif
+
tree (*lang_type_promotes_to) PARAMS ((tree));
*************** std_expand_builtin_va_arg (valist, type)
*** 1968,1972 ****
/* Get AP. */
addr_tree = valist;
! if (BYTES_BIG_ENDIAN)
{
/* Small args are padded downward. */
--- 1972,1976 ----
/* Get AP. */
addr_tree = valist;
! if (PAD_VARARGS_DOWN)
{
/* Small args are padded downward. */
Index: config/mips/mips.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/mips/mips.h,v
retrieving revision 1.83
diff -c -2 -p -r1.83 mips.h
*** mips.h 2000/01/14 14:31:43 1.83
--- mips.h 2000/01/14 16:00:06
***************
*** 1,4 ****
/* Definitions of target machine for GNU compiler. MIPS version.
! Copyright (C) 1989, 90-98, 1999 Free Software Foundation, Inc.
Contributed by A. Lichnewsky (lich@inria.inria.fr).
Changed by Michael Meissner (meissner@osf.org).
--- 1,4 ----
/* Definitions of target machine for GNU compiler. MIPS version.
! Copyright (C) 1989, 90-98, 1999, 2000 Free Software Foundation, Inc.
Contributed by A. Lichnewsky (lich@inria.inria.fr).
Changed by Michael Meissner (meissner@osf.org).
*************** do { \
*** 1439,1442 ****
--- 1439,1447 ----
|| TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))
+
+ /* Force right-alignment for small varargs in 32 bit little_endian mode */
+
+ #define PAD_VARARGS_DOWN (TARGET_64BIT ? BYTES_BIG_ENDIAN : !BYTES_BIG_ENDIAN)
+
/* Define this macro if an argument declared as `char' or `short' in a
prototype should actually be passed as an `int'. In addition to
Index: tm.texi
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tm.texi,v
retrieving revision 1.104
diff -c -2 -p -r1.104 tm.texi
*** tm.texi 2000/01/13 10:43:33 1.104
--- tm.texi 2000/01/14 16:48:43
*************** big-endian machines, the default is to p
*** 2944,2947 ****
--- 2944,2955 ----
constant size shorter than an @code{int}, and upward otherwise.
+ @findex PAD_VARARGS_DOWN
+ @item PAD_VARARGS_DOWN
+ If defined, a C expression which determines whether the default
+ implementation of va_arg will attempt to pad down before reading the
+ next argument, if that argument is smaller than its aligned space as
+ controlled by @code{PARM_BOUNDARY}. If this macro is not defined, all such
+ arguments are padded down if @code{BYTES_BIG_ENDIAN} is true.
+
@findex FUNCTION_ARG_BOUNDARY
@item FUNCTION_ARG_BOUNDARY (@var{mode}, @var{type})