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]
Other format: [Raw text]

Re: MIPS: va_arg is unable to correct extract an empty zero-length array


Nick Clifton <nickc@redhat.com> writes:
> 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.

Interesting test case :-)  Certainly looks like a genuine bug though.
I see the same thing happens for varargs that are passed on the stack
as well (not just those passed in registers).

Fortunately, it looks like the bug is on the varargs side, so no ABI
change is needed.  Does the attached patch work?  I'll try to do a
full test this weekend.

Richard


Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	(revision 170697)
+++ gcc/config/mips/mips.c	(working copy)
@@ -5625,6 +5625,10 @@
 		     NULL_TREE);
       size = int_size_in_bytes (type);
 
+      /* Even zero-sized arguments occupy one byte.  */
+      if (size == 0)
+	size = 1;
+
       if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT
 	  && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE)
 	{


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