From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73778 invoked by alias); 13 Sep 2017 20:03:51 -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 72521 invoked by uid 89); 13 Sep 2017 20:03:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS,URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 Sep 2017 20:03:48 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1dsDsv-0000vp-J8 from joseph_myers@mentor.com ; Wed, 13 Sep 2017 13:03:45 -0700 Received: from digraph.polyomino.org.uk (137.202.0.87) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Wed, 13 Sep 2017 21:03:42 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.86_2) (envelope-from ) id 1dsDso-0007ZT-2e; Wed, 13 Sep 2017 20:03:38 +0000 Date: Wed, 13 Sep 2017 20:03:00 -0000 From: Joseph Myers To: Bernd Edlinger CC: "gcc-patches@gcc.gnu.org" , Nathan Sidwell , Jason Merrill , Marek Polacek Subject: Re: [PATCH] Add a -Wcast-align=strict warning In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-SW-Source: 2017-09/txt/msg00842.txt.bz2 On Wed, 13 Sep 2017, Bernd Edlinger wrote: > On 09/13/17 19:06, Joseph Myers wrote: > > What does this warning do in cases where a type has different alignments > > inside and outside structs? I'm thinking of something like > > > > struct s { long long x; } *p; > > /* ... */ > > (long long *)p > > > > on 32-bit x86 - where long long's preferred alignment is 8 bytes, but in > > structures it's 4 bytes. (Likewise for double in place of long long.) I > > think a warning for a (long long *)p cast might be surprising in that > > case. > > > > Well, yes this does get a warning. But doesn't that cast then violate > the underlying alignment requirement of long long* ? That's the difference between preferred alignment (__alignof__) and alignment required in all contexts (C11 _Alignof). The above seems valid, just like it's valid to take the address of a long long struct element. That is, the alignment for the target of a pointer to long long is really 4 bytes here, even though the alignment for a standalone long long object is 8 bytes. And there's a case for the warning to look at the required alignment in all contexts, not TYPE_ALIGN. -- Joseph S. Myers joseph@codesourcery.com