This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix small structure passing on x86-64
- From: Jan Hubicka <hubicka at ucw dot cz>
- To: Eric Botcazou <ebotcazou at adacore dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 11 Nov 2008 18:30:47 +0100
- Subject: Re: [PATCH] Fix small structure passing on x86-64
- References: <200810311146.58286.ebotcazou@adacore.com>
> Hi,
>
> the structure
>
> struct S { char c; char arr[4]; float f; };
>
> is incorrect passed on x86-64/Linux with every C compiler I tried: only the
> first 4 bytes and the float are passed (in registers), the 5th byte is lost.
> That's because the first word has partial integer class X86_64_INTEGERSI_CLASS
> instead of full integer class X86_64_INTEGER_CLASS.
> if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
> subclasses[0] = X86_64_SSE_CLASS;
> - if (subclasses[0] == X86_64_INTEGERSI_CLASS && bytes != 4)
> + if (subclasses[0] == X86_64_INTEGERSI_CLASS
> + && !((bit_offset % 64) == 0 && bytes == 4))
the test here is still bit confused. It should test if the whole array
fits in lower 4 bytes that would be somehting like
(bit_offset + 7) / 8 + bytes <= 4
There are very intersting problems related to this and reading past end
of the structure possibly causing segfault. I am working on more
complette patch.
Honza
> subclasses[0] = X86_64_INTEGER_CLASS;
>
> for (i = 0; i < words; i++)
> struct S { char c; char arr[4]; float f; };
>
> char A[4] = { '1', '2', '3', '4' };
>
> void foo (struct S s)
> {
> if (__builtin_memcmp (s.arr, A, 4))
> __builtin_abort ();
> }
>
> int main (void)
> {
> struct S s;
> __builtin_memcpy (s.arr, A, 4);
> foo (s);
> return 0;
> }