From: Richard Guenther <richard.guenther@gmail.com>
To: Paolo Bonzini <bonzini@gnu.org>
Cc: Ian Lance Taylor <iant@google.com>,
Nathan Boley <npboley@gmail.com>,
gcc@gcc.gnu.org
Subject: Re: Possible Bug
Date: Mon, 28 Mar 2011 12:14:00 -0000 [thread overview]
Message-ID: <AANLkTikyjxDpEpGj8kwt_4VhYgiYbfnRwm_8HudXB5uy@mail.gmail.com> (raw)
In-Reply-To: <4D9072B3.708@gnu.org>
On Mon, Mar 28, 2011 at 1:36 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
> On 03/28/2011 01:06 PM, Richard Guenther wrote:
>>>
>>> /* GCC uses 8-byte loads and register passing even though sizeof = 6 */
>>> typedef struct __attribute__((__packed__))
>>> {
>>> unsigned chr :16;
>>> unsigned loc :32;
>>> } GENOME_LOC_TYPE_2;
>>>
>>> //#define GENOME_LOC_TYPE GENOME_LOC_TYPE_1
>>> #define GENOME_LOC_TYPE GENOME_LOC_TYPE_2
>>>
>>> static __attribute__((__noclone__,__noinline__))
>>> int f(GENOME_LOC_TYPE x)
>>> {
>>> return x.loc;
>>> }
>>>
>>> GENOME_LOC_TYPE h;
>>> GENOME_LOC_TYPE *g =&h;
>>>
>>> int
>>> main()
>>> {
>>> printf ("%d %d\n", sizeof (GENOME_LOC_TYPE),
>>> __alignof__(GENOME_LOC_TYPE));
>>> return f(*g);
>>> }
>>>
>>>
>>> Both definitions have a (sizeof = 6, alignof = 1) but GCC loads the
>>> second
>>> with an 8-byte load. It's really an ugly bug if I understood it
>>> correctly,
>>> because I would have expected the second struct to have sizeof = 8. The
>>> two
>>> final bytes are not padding, they are what's left of the unsigned int
>>> from
>>> which the bitfields are carved. If that were the correct fix for the
>>> bug,
>>> it would be a change to the ABI.
>>
>> At expansion time we have the following for the call argument:
>>
>> <mem_ref 0x7ffff7ff9118
>> type<record_type 0x7ffff5b295e8 GENOME_LOC_TYPE_2 packed type_0 BLK
>> size<integer_cst 0x7ffff5b256b8 constant 48>
>> unit size<integer_cst 0x7ffff5b25708 constant 6>
>> align 8 symtab 0 alias set -1 canonical type 0x7ffff5b29540
>>
>> which looks ok to me.
>
> It already isn't, why is the alignment 8 if __alignof__ (GENOME_LOC_TYPE_2)
> is 1?
>
> The other question is a layout question, should the packed attribute affect
> the removal of padding from the last bitfield element? That's a very
> different kind of padding, and it affects whether the size of the struct
> should be 6 or 8? Note this is slightly different from the problem in
> -Wpacked-bitfield-compat.
>
> In fact, should the poster's desired layout (the same as GENOME_LOC_TYPE_1,
> I guess) be achievable at all with bitfields, even in combination with the
> packed attribute?
Btw, this looks like http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36043
Richard.
> Paolo
>
next prev parent reply other threads:[~2011-03-28 11:47 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-26 20:28 Nathan Boley
2011-03-27 7:38 ` Ian Lance Taylor
2011-03-28 11:06 ` Paolo Bonzini
2011-03-28 11:28 ` Richard Guenther
2011-03-28 11:47 ` Paolo Bonzini
2011-03-28 12:14 ` Richard Guenther [this message]
2011-03-28 13:37 ` Michael Matz
2011-03-28 13:54 ` Paolo Bonzini
2011-03-28 14:37 ` Richard Guenther
2011-03-29 16:03 ` Nathan Boley
-- strict thread matches above, loose matches on Subject: below --
2003-01-31 0:33 possible bug Andrew Morton
2003-01-31 0:36 ` Jan Hubicka
2003-01-31 0:56 ` Andrew Morton
2003-01-31 8:08 ` Alexandre Oliva
2003-01-31 10:48 ` Fergus Henderson
1999-07-25 17:52 Manush Dodunekov
1999-07-26 10:57 ` Alexandre Oliva
1999-07-27 3:27 ` Manush Dodunekov
1999-07-27 3:37 ` Alexandre Oliva
1999-07-31 23:33 ` Alexandre Oliva
1999-07-31 23:33 ` Manush Dodunekov
1999-07-31 23:33 ` Alexandre Oliva
1999-07-31 23:33 ` Manush Dodunekov
1997-12-12 15:46 Possible Bug Mike Sullivan
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=AANLkTikyjxDpEpGj8kwt_4VhYgiYbfnRwm_8HudXB5uy@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=bonzini@gnu.org \
--cc=gcc@gcc.gnu.org \
--cc=iant@google.com \
--cc=npboley@gmail.com \
/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).