From: Joseph Myers <joseph@codesourcery.com>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Nathan Sidwell <nathan@acm.org>, Jason Merrill <jason@redhat.com>,
Marek Polacek <polacek@redhat.com>
Subject: Re: [PATCH] Add a -Wcast-align=strict warning
Date: Wed, 13 Sep 2017 20:03:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.20.1709131959290.28319@digraph.polyomino.org.uk> (raw)
In-Reply-To: <AM5PR0701MB26579114FABD8F8F4D2CEB2CE46E0@AM5PR0701MB2657.eurprd07.prod.outlook.com>
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
next prev parent reply other threads:[~2017-09-13 20:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-04 8:07 Bernd Edlinger
2017-09-11 13:53 ` [PING] " Bernd Edlinger
2017-09-13 17:06 ` Joseph Myers
2017-09-13 19:52 ` Bernd Edlinger
2017-09-13 20:03 ` Joseph Myers [this message]
2017-09-13 20:55 ` Bernd Edlinger
2017-09-13 20:57 ` Joseph Myers
2017-09-14 16:33 ` [PATCHv2] " Bernd Edlinger
2017-09-15 15:51 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1709131959290.28319@digraph.polyomino.org.uk \
--to=joseph@codesourcery.com \
--cc=bernd.edlinger@hotmail.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).