This is the mail archive of the gcc-bugs@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]

va_arg( , char) problem


Hello,
it seems that I have encountered a bug in gcc 2.95.3.
va_arg() does not like the "char" type.

This might be related to the comment in:
/usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/include/stdarg.h:

| /* stdarg.h for GNU.
|    Note that the type used in va_arg is supposed to match the
|    actual type **after default promotions**.
|    Thus, va_arg (..., short) is not valid.  */

But see the problem for yourself:

$gcc -v --save-temps -O2 va_arg_test.c
Reading specs from /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease/franzo)
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -DPPC -D__ELF__ -Dpowerpc -D__PPC__ -D__ELF__ -D__powerpc__ -D__PPC -D__powerpc -Acpu(powerpc) -Amachine(powerpc) -D__CHAR_UNSIGNED__ -D__OPTIMIZE__ -D_CALL_SYSV -D_BIG_ENDIAN -D__BIG_ENDIAN__ -Amachine(bigendian) -D_ARCH_PPC -D__unix__ -D__linux__ -Dunix -D__unix -Dlinux -D__linux -Asystem(unix) -Asystem(posix) va_arg_test.c va_arg_test.i
GNU CPP version 2.95.3 19991030 (prerelease/franzo) (PowerPC GNU/Linux)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../ppc-redhat-linux/include
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../include/g++-3
End of omitted list.
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cc1 va_arg_test.i -quiet -dumpbase va_arg_test.c -O2 -version -o va_arg_test.s
GNU C version 2.95.3 19991030 (prerelease/franzo) (ppc-redhat-linux) compiled by GNU C version 2.95.3 19991030 (prerelease/franzo).
va_arg_test.c: In function `main':
va_arg_test.c:26: warning: return type of `main' is not `int'
 as -mppc -V -Qy -o va_arg_test.o va_arg_test.s
GNU assembler version 2.9.5 (ppc-redhat-linux) using BFD version 2.9.5.0.41
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/collect2 -m elf32ppclinux -dynamic-linker /lib/ld.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/crtbegin.o -L/usr/lib/gcc-lib/ppc-redhat-linux/2.95.3 va_arg_test.o /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/libgcc.a -lc /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/libgcc.a /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/crtend.o /usr/lib/crtn.o
va_arg_test.o: In function `va_arg_test':
va_arg_test.o(.text+0x80): undefined reference to `__va_arg_type_violation'
va_arg_test.o(.text+0x80): relocation truncated to fit: R_PPC_REL24 __va_arg_type_violation
collect2: ld returned 1 exit status


$ gcc -v --save-temps va_arg_test.c 
Reading specs from /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease/franzo)
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -DPPC -D__ELF__ -Dpowerpc -D__PPC__ -D__ELF__ -D__powerpc__ -D__PPC -D__powerpc -Acpu(powerpc) -Amachine(powerpc) -D__CHAR_UNSIGNED__ -D_CALL_SYSV -D_BIG_ENDIAN -D__BIG_ENDIAN__ -Amachine(bigendian) -D_ARCH_PPC -D__unix__ -D__linux__ -Dunix -D__unix -Dlinux -D__linux -Asystem(unix) -Asystem(posix) va_arg_test.c va_arg_test.i
GNU CPP version 2.95.3 19991030 (prerelease/franzo) (PowerPC GNU/Linux)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../ppc-redhat-linux/include
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/../../../../include/g++-3
End of omitted list.
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/cc1 va_arg_test.i -quiet -dumpbase va_arg_test.c -version -o va_arg_test.s
GNU C version 2.95.3 19991030 (prerelease/franzo) (ppc-redhat-linux) compiled by GNU C version 2.95.3 19991030 (prerelease/franzo).
va_arg_test.c: In function `main':
va_arg_test.c:26: warning: return type of `main' is not `int'
 as -mppc -V -Qy -o va_arg_test.o va_arg_test.s
GNU assembler version 2.9.5 (ppc-redhat-linux) using BFD version 2.9.5.0.41
 /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/collect2 -m elf32ppclinux -dynamic-linker /lib/ld.so.1 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/crtbegin.o -L/usr/lib/gcc-lib/ppc-redhat-linux/2.95.3 va_arg_test.o /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/libgcc.a -lc /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/libgcc.a /usr/lib/gcc-lib/ppc-redhat-linux/2.95.3/crtend.o /usr/lib/crtn.o

$ ./a.out
><
>d<


In case that the "char" type to va_arg is really illegal as already hinted upon
on the stdarg.h file there should be an error message somehow. :)

The solution seems to be to not use va_arg with the char type.
Thanks for the work on gcc. 
	Bernhard

-- 
Professional Service around Free Software                (intevation.net)  
The FreeGIS Project				            (freegis.org)
Association for a Free Informational Infrastructure            (ffii.org)
#include <stdio.h>
#include <stdarg.h>

      va_arg_test(char *format, ...)
       {
       va_list argp;
       char c;
 
       va_start(argp, format);
       printf(">%c<\n",	(int)va_arg(argp,char) );
       va_end(argp);
       return 0;
       }

      va_arg_testi(char *format, ...)
       {
       va_list argp;
       int c;
 
       va_start(argp, format);
       printf(">%c<\n", va_arg(argp,int));
       va_end(argp);
       return 0;
       }

void main(void){
	va_arg_test("Hello",'d');
	va_arg_testi("Hello",'d');
}

va_arg_test.optimised.i.gz

va_arg_test.i.gz

PGP signature


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