This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFA and RFC: tweak -fstrict-aliasing docs, provide pointer-cast example
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Andrew Haley" <aph at redhat dot com>
- Cc: "Hans-Peter Nilsson" <hans-peter dot nilsson at axis dot com>, gcc-patches at gcc dot gnu dot org, gcc at gcc dot gnu dot org
- Date: Wed, 25 Jun 2008 16:22:49 +0200
- Subject: Re: RFA and RFC: tweak -fstrict-aliasing docs, provide pointer-cast example
- References: <200806241019.m5OAJb9j015429@ignucius.se.axis.com> <48625078.8040605@redhat.com>
On Wed, Jun 25, 2008 at 4:04 PM, Andrew Haley <aph@redhat.com> wrote:
> Hans-Peter Nilsson wrote:
>>> Date: Tue, 24 Jun 2008 10:36:15 +0100
>>> From: Andrew Haley <aph@redhat.com>
>>
>>> I thought cast-through-pointer-to-union didn't work and was already
>>> disallowed; we've been around all this already.
>>
>> We also bless assignments through unions, and this could be
>> argued as assigning through a union, albeit casted.
>>
>>> This patch of yours
>>> already documents uncontroversial behaviour.
>>
>> That's what I hope, but the existence of that code together in
>> an *else* clause of #ifdef YES_ALIAS by a well-known author
>> makes it de-facto controversial IMHO. Note also that another
>> maintainer thought the code to be valid; see the PR.
>
> So I see. I'm pretty sure that the compiler's alias analysis won't
> think it's valid, but I haven't checked.
Right. It happily "mis-"optimizes it. And on a second thought I
agree the construct is invalid.
> Do we actually document anywhere that a C++-style type pun along the lines
> of
>
> reinterpret_cast<T&>(x)
>
> will not work? I'm guessing it probably won't, and that the union trick
> is the only thing we do support.
This is not a "pun", it only re-interprets the pointer _value_, not what
it points to.
Richard.