From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24705 invoked by alias); 28 Mar 2011 11:36:29 -0000 Received: (qmail 24619 invoked by uid 22791); 28 Mar 2011 11:36:29 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-pw0-f47.google.com (HELO mail-pw0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Mar 2011 11:36:24 +0000 Received: by pwj9 with SMTP id 9so1111920pwj.20 for ; Mon, 28 Mar 2011 04:36:24 -0700 (PDT) Received: by 10.142.248.17 with SMTP id v17mr3476778wfh.260.1301312183929; Mon, 28 Mar 2011 04:36:23 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-210-217.ip51.fastwebnet.it [93.34.210.217]) by mx.google.com with ESMTPS id s41sm5778087wfc.3.2011.03.28.04.36.21 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Mar 2011 04:36:23 -0700 (PDT) Message-ID: <4D9072B3.708@gnu.org> Date: Mon, 28 Mar 2011 11:47:00 -0000 From: Paolo Bonzini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 MIME-Version: 1.0 To: Richard Guenther CC: Ian Lance Taylor , Nathan Boley , gcc@gcc.gnu.org Subject: Re: Possible Bug References: <4D9065FD.6060100@gnu.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2011-03/txt/msg00444.txt.bz2 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: > > type size > unit size > 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? Paolo