From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61596 invoked by alias); 7 Apr 2015 14:51:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 61577 invoked by uid 89); 7 Apr 2015 14:51:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: arjuna.pair.com Received: from arjuna.pair.com (HELO arjuna.pair.com) (209.68.5.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 07 Apr 2015 14:51:07 +0000 Received: by arjuna.pair.com (Postfix, from userid 3006) id CE5BD8A3DA; Tue, 7 Apr 2015 10:51:01 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by arjuna.pair.com (Postfix) with ESMTP id A6D878A38D; Tue, 7 Apr 2015 10:51:01 -0400 (EDT) Date: Tue, 07 Apr 2015 14:51:00 -0000 From: Hans-Peter Nilsson To: Jonathan Wakely cc: Richard Henderson , libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [libstdc++/65033] Give alignment info to libatomic In-Reply-To: <20150407131252.GB9755@redhat.com> Message-ID: References: <54DD19B7.6060401@redhat.com> <20150403141333.GY9755@redhat.com> <20150407094458.GA9755@redhat.com> <20150407131252.GB9755@redhat.com> User-Agent: Alpine 2.02 (BSF 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00255.txt.bz2 On Tue, 7 Apr 2015, Jonathan Wakely wrote: > On 07/04/15 06:51 -0400, Hans-Peter Nilsson wrote: > > On Tue, 7 Apr 2015, Jonathan Wakely wrote: > > > On 05/04/15 21:07 -0400, Hans-Peter Nilsson wrote: > > > > We did specify that with the alignas. Is the alignof always > > > > exactly the same as an alignas, if one is specified? (And will > > > > that not change in a future amendment, standard and/or > > > > implementation?) Either way, is there a test-case to guard all > > > > this? > > > > > > The language guarantees that's what alignas() does, if the argument is > > > a valid alignment (which it must be if we derive it from some other > > > type's alignment). > > > > I'm more worried about alignof reporting a higher value for a > > specific object than alignas to be wrong. > > That shouldn't be possible because the C++ standard says it's an error > to use alignas with a less strict alignment than would be used if it > was omitted, i.e. an error to use alignas with a value less than the > result alignof would give. However, G++ doesn't reject it (PR65685). > > It still won't be possible here, because the alignas value we use is > not less than alignof(_Tp). That's not what I meant. My worry is there being a case where alignof yields a *higher* value than the one that the alignas specified. > > Your question quoted just below seems to indicate a similar > > worry. > > I was thinking about cases like this: > > struct __attribute__((packed)) Bad { > char c; > std::atomic a; > }; > > But G++ ignores the packed attribute here, which is good (Clang > doesn't seem to ignore it, and mis-aligns the atomic). I was more thinking of something like: #include #include using std::cout; using std::endl; struct SoSo { double d; int x alignas(sizeof(int)); }; SoSo s __attribute__((__aligned__(16))); int main(void) { cout << "alignof(s): " << alignof(s) << endl; cout << "alignof(s.d): " << alignof(s.d) << endl; cout << "alignof(s.x): " << alignof(s.x) << endl; } in which I fear s.x would get an alignof the same as the s.d or s, now or after a while, i.e. higher than specified. (I get for cris-elf at revision 221891: alignof(s): 16 alignof(s.d): 1 alignof(s.x): 4 which is kind-of-expected except I thought s.d would get the s alignment so that just leaves it open whether that could possibly change.) brgds, H-P