This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
MIPS: va_arg is unable to correct extract an empty zero-length array
- From: Nick Clifton <nickc at redhat dot com>
- To: echristo at apple dot com, rdsandiford at googlemail dot com
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Mar 2011 17:53:52 +0000
- Subject: MIPS: va_arg is unable to correct extract an empty zero-length array
Hi Eric, Hi Richard,
A customer has reported the following bug with the MIPS target. Since
it is for a GNU extension to the C language (zero-length arrays) that
is being used in a non-intended fashion (the zero-length array is in a
structure with no other fields) I doubt if you will want to
investigate the problem too much, but I thought that it was worth
reporting anyway:
% mips64vr-elf-gcc -mgp32 -O2 -Tddb.ld -march=vr5500 bug.c
% mips64vr-elf-run a.out
assertion "arg4 == va4" failed: file "bug.c", line 40, function: foo
As an aside if the type3 structure in bug.c is given another,
non-zero-length field, then the test passes.
Cheers
Nick
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
typedef int * type1;
typedef struct
{
union u1 { double f1; long int f2; } f3[0];
} type3;
typedef int type4;
static type1 arg1 = 0;
static double arg2 = 1.0;
static type3 arg3 = {{}};
static type4 arg4 = 0x12345678;
void
foo (double parm,
...)
{
va_list ap;
type1 va1;
double va2;
type3 va3;
type4 va4;
va_start (ap, parm);
va1 = va_arg (ap, type1);
assert (arg1 == va1);
va2 = va_arg (ap, double);
assert (arg2 == va2);
va3 = va_arg (ap, type3);
va4 = va_arg (ap, type4);
assert (arg4 == va4);
va_end (ap);
}
int
main (void)
{
foo (1.0, arg1, arg2, arg3, arg4);
return 0;
}