https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100653
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> Attached test case produces invalid results with -O2, good with -O1.
See the manual:
Moreover, the use of type punning or aliasing to toggle the storage
order is not supported; that is to say, a given scalar object
cannot be accessed through distinct types that assign a different
storage order to it.
typedef struct tIp6Addr
{
unsigned int s6_addr32[4];
} tIp6Addr;
struct _tBeTimNetAddr
{
unsigned char isIPv4;
union
{
unsigned int addr;
tIp6Addr addr6;
} BB_MSG_ENDIANNESS u;
} BB_MSG_ENDIANNESS;
_tBeTimNetAddr.u.addr6.s6_addr32[0] is accessed in little-endian and
_tBeTimNetAddr.u.addr is accessed in big-endian, but they are the same scalar.