https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101061

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> ---
On Tue, 15 Jun 2021, alexander.gr...@tu-dresden.de wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101061
> 
> --- Comment #3 from Alexander Grund <alexander.gr...@tu-dresden.de> ---
> You are right, it actually seems to be the combination of those to, so -O2
> -fno-strict-aliasing and -O2 -fno-tree-vrp both make it work.
> 
> The layout-compatible refers to the "common initial sequence" that is allowed
> to be inspected for inactive union members, see the link.

We definitely do not implement the common initial sequence rule.  Where
this manifests is when you for example have

 struct X { int i; };
 struct Y { int i; int j; } *a;

and access *(struct X *)a - thus when you do an access with an effective
type of the _aggregate_ that forms the common initial sequence.  Accessing
the members via a pointer to their type works fine (here int *).  Note
that ((struct X *)a)->i also constitutes an access of an object of
type X and thus is not implemented with the common initial sequence
rule in mind.

Note this is never going to change for GCC since this rule is not
well thought out (to name it politely ;)).

You can, as workaround use sth like

struct X { int i; } __attribute__((may_alias));

where the indirect accesses to type X will alias everything.
Or alternatively use type composition.

Reply via email to