public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Eric Botcazou <ebotcazou@adacore.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix small structure passing on x86-64
Date: Tue, 11 Nov 2008 18:00:00 -0000	[thread overview]
Message-ID: <20081111173046.GB27401@atrey.karlin.mff.cuni.cz> (raw)
In-Reply-To: <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;
> }

  reply	other threads:[~2008-11-11 17:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-31 11:50 Eric Botcazou
2008-11-11 18:00 ` Jan Hubicka [this message]
2008-11-11 18:22   ` Eric Botcazou
2008-11-11 18:41     ` Jan Hubicka
2008-11-12 17:07 ` Jan Hubicka
2008-11-13 15:19   ` Eric Botcazou
2008-11-13 16:24     ` Jan Hubicka
2008-10-31 20:30 Uros Bizjak
2008-11-11 16:51 ` Richard Guenther
2008-11-11 16:56   ` H.J. Lu
2008-11-11 17:57     ` Michael Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081111173046.GB27401@atrey.karlin.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).