From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) by sourceware.org (Postfix) with ESMTPS id 8065F3857352 for ; Tue, 24 May 2022 14:29:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8065F3857352 Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id tUqsnmKTTwtwGtVXPnVMLP; Tue, 24 May 2022 14:29:31 +0000 Received: from kylheku.com ([70.79.182.7]) by cmsmtp with ESMTPA id tVXTn20LjsF60tVXUnf6PS; Tue, 24 May 2022 14:29:36 +0000 X-Authority-Analysis: v=2.4 cv=Z8n/oVdA c=1 sm=1 tr=0 ts=628cebd0 a=pMSlDXUwMa7SJ1EIez8PdQ==:117 a=pMSlDXUwMa7SJ1EIez8PdQ==:17 a=xqWC_Br6kY4A:10 a=kj9zAlcOel0A:10 a=oZkIemNP1mAA:10 a=j6R_WNsobC0NYlDy6L0A:9 a=CjuIK1q_8ugA:10 Received: from localhost ([::1] helo=mail.kylheku.com) by kylheku.com with esmtp (Exim 4.94.2) (envelope-from ) id 1ntVSX-009ATV-Mi for gcc-help@gcc.gnu.org; Tue, 24 May 2022 07:29:35 -0700 MIME-Version: 1.0 Date: Tue, 24 May 2022 07:29:35 -0700 From: Kaz Kylheku To: gcc-help@gcc.gnu.org Subject: Question about bitfields with aligned attribute. User-Agent: Roundcube Webmail/1.4.13 Message-ID: <4d9dc2bd390f336e05b092316986b1e4@kylheku.com> X-Sender: kaz@kylheku.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4xfHRiDSSdb6/bV+KEk9YZAy4e6Zv7VOb3fqdZQwhWjkVoWSWL3T1Bj+dRkUfTIFjBGoYtCvOAFN7A0UlALPanBUJjNw0ZCO+4klYWdvd6M0Cne38aeLhk av9TjWrWKgXDEPn4OBuzXYPZpMy622nxlbTYOSLUuzvKNuPFjJyoy0I/zT7rb99gVksNQCBUiy7AGw== X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2022 14:29:39 -0000 Hi all, I'm observing two contradictory effects in the treatment this structure: struct s16 { uint8_t x; __attribute__((aligned (2))) uint32_t a : 7; __attribute__((aligned (2))) uint32_t b : 7; }; Firstly, the aligned attribute is documented as only being capable of increasing alignment. Yet, what is observed is that it's being honored: bitfield a is placed at offset 2, and b at offset 4. So there is an exception to the aligned attribute's "strengthen only" rule for bitfields? Where is this documented? Secondly, in spite of the aligned attribute being honored, the structure is given two bytes of padding, making it 8 bytes. Why is that? Nothing in the structure has more than 2 byte alignment, which requires one byte to make a size of six. What are the exact rules here? Does the bitfield member carry two alignment properties: one coming from the attribute syntax, and one from the uint32_t type? Such that the former is allowed to be smaller, even in the absence of packed? And then the allocation of the bitfield takes into account the former, but both are considered for the purposes of struct alignment? Thanks.