RFR: 8145096: Undefined behaviour in HotSpot

Andrew Dinn adinn at redhat.com
Thu Dec 17 09:27:43 UTC 2015


On 17/12/15 00:26, Kim Barrett wrote:
> Regarding generation of "bogus" code, consider this function:
> 
> int foo(int x) {
>   union { int i; unsigned u; };
>   u = x;
>   return i;
> }
> 
> The statement "u = x;" is a dead assignment.  Nowhere is u accessed
> directly; nor is there a access of something that could alias u, since
> there aren't any pointers/references taken.  The access of i doesn't
> count, since accessing a union member other than the last one assigned
> is UB.  Since the assignment is dead, the compiler may elide it.

Hmm, no aliasing? That's an /interesting/ point of view. If only it were
correct (... by some criterion more well-founded than
committee-sanctioned derogation :-).

> Another way of looking at it is that i is nowhere assigned, making the
> statement "return i;" problematic.  There is no connection between the
> assignment of u and the access of i.  The compiler might choose any
> value to return, including a trap-representation.

Hmm, no connection? Ditto!

regards,


Andrew Dinn
-----------



More information about the hotspot-dev mailing list