From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp002.apm-internet.net (smtp002.apm-internet.net [85.119.248.221]) by sourceware.org (Postfix) with ESMTPS id 461943858D28 for ; Sun, 4 Sep 2022 13:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 461943858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=sandoe.co.uk Received: (qmail 65763 invoked from network); 4 Sep 2022 13:32:57 -0000 X-APM-Out-ID: 16622983776576 X-APM-Authkey: 257869/1(257869/1) 5 Received: from unknown (HELO ?192.168.1.95?) (81.138.1.83) by smtp002.apm-internet.net with SMTP; 4 Sep 2022 13:32:57 -0000 From: Iain Sandoe Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: An odd case with structure field alignment. Message-Id: <88B0BAB2-A649-406E-B536-EE18431858F1@sandoe.co.uk> Date: Sun, 4 Sep 2022 14:32:56 +0100 To: GCC Development X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00,KAM_COUK,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,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 List-Id: Hi, I am clearly missing something here =E2=80=A6 can someone point out = where it is? = https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Variable-Attributes.html#Variab= le%20Attributes in the discussion of applying this to structure fields: "The aligned attribute can only increase the alignment; but you can = decrease it by specifying packed as well." Consider: struct odd { int * __attribute__((aligned(2))) a; char c; }; I would expect, given reading of the information on the aligned = attribute, that the under-alignment of a would be ignored (since there = is no packed attribute on either the field or the struct). However, on x86_64, powerpc64 linux and x86_64, powerpc Darwin, I see = that the size of the struct is sizeof(pointer) + 2 and the alignment is = 2. OTOH: struct OK { int __attribute__((aligned(2))) a; char c; }; behaves as expected (the under-alignment is ignored, silently). as does this=E2=80=A6 struct maybe { int *a __attribute__((aligned(2))); char c; }; * the type of the pointer does not seem to be relevant (i.e. AFAICT the = behaviour is the same for char * etc.) Is there some special rule about pointers that I have not found ? [it=E2=80=99s making an ABI mismatch with clang, which treats the int * = as expected from the documentation quoted above] cheers Iain