[gnu.gcc.bug] Varargs Bug on Sparc

frank@Morgan.COM (Frank Wortner) (01/21/89)

Machine/OS:	Sun-4/SunOS 4.0

GCC 1.32 won't compile the program "va-test.c".  Sun's CC compiles
the program without complaint, and the result executes correctly.
This problem seems to be related to the implementation of "va-sparc.h".
I've enclosed my own version of this file, "my-va-sparc.h".  This one
*seems* to work OK, but I'd like others to try it.  Try
	gcc va-test.c
and then try
	gcc -DMY_VARARGS va-test.c

BTW, I spotted this problem while trying to compile GAWK 2.00 Beta with
GCC.  The file "awk5.c" contains code similar to that in "va-test.c".

						Frank
-------------------------------------------------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	va-test.c
#	my-va-sparc.h
# This archive created: Fri Jan 20 15:51:19 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'va-test.c'" '(421 characters)'
if test -f 'va-test.c'
then
	echo shar: will not over-write existing file "'va-test.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'va-test.c'
	X#include <stdio.h>
	X
	X#ifdef MY_VARARGS
	X#  include "./my-va-sparc.h"
	X#else
	X#  include <varargs.h>
	X#endif
	X
	Xvoid test1(ap)
	Xva_list ap;
	X{
	X  char *fmt;
	X  double f;
	X
	X  f = va_arg(ap, double);
	X  printf("f = %f\n", f);
	X  fmt = va_arg(ap, char *);
	X  vprintf(fmt, ap);
	X}
	X
	Xvoid test(va_alist)
	Xva_dcl
	X{
	X  va_list ap;
	X    
	X  va_start(ap);
	X  test1(ap);
	X  va_end(ap);
	X}
	X    
	X    
	X
	Xvoid main()
	X{
	X  test(5.12, "%s %d\n", "arg1", -234);
	X}
	X
SHAR_EOF
if test 421 -ne "`wc -c < 'va-test.c'`"
then
	echo shar: error transmitting "'va-test.c'" '(should have been 421 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'my-va-sparc.h'" '(775 characters)'
if test -f 'my-va-sparc.h'
then
	echo shar: will not over-write existing file "'my-va-sparc.h'"
else
sed 's/^	X//' << \SHAR_EOF > 'my-va-sparc.h'
	X#ifdef sparc
	X/* Frank Wortner's replacement for the normal GCC 1.32 va-sparc.h.
	X** This implementation is (more or less) compatible with Sun's, so you can
	X** use it with Sun's libraries.
	X*/
	X
	X#define va_dcl int __fake_arg;
	X#define va_alist __fake_arg
	Xtypedef void *va_list;
	X
	X/* Amount of space required in an argument list for an arg of type TYPE.
	X   TYPE may alternatively be an expression whose type is used.  */
	X
	X#define __va_rounded_size(TYPE)  \
	X  (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
	X
	X#define va_start(AP) 						\
	X (__builtin_saveregs (),						\
	X  AP = ((void *) &__fake_arg))
	X
	X#define va_end(AP)
	X
	X#define va_arg(AP, TYPE)						\
	X (AP += __va_rounded_size (TYPE),					\
	X  *((TYPE *) (AP - __va_rounded_size (TYPE))))
	X
	X
	X#endif /* sparc */
SHAR_EOF
if test 775 -ne "`wc -c < 'my-va-sparc.h'`"
then
	echo shar: error transmitting "'my-va-sparc.h'" '(should have been 775 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0

-- 
						Frank

"Computers are mistake amplifiers."