Undefined behavior due to 6.5.16.1p3

2015-03-09 Thread Robbert Krebbers
I was wondering whether GCC uses 6.5.16.1p3 of the C11 standard as a license to perform certain optimizations. If so, could anyone provide me an example program. In particular, I am interested about the "then the overlap shall be exact" part of 6.5.16.1p3: If the value being stored in an o

Re: Undefined behavior due to 6.5.16.1p3

2015-03-10 Thread Robbert Krebbers
Dear Richard, On 03/10/2015 09:51 AM, Richard Biener wrote: struct X { int i; int j; }; int foo (struct X *p, struct X *q) { q->j = 1; p->i = 0; return q->j; } will optimize to return 1. If *p and *q were allowed to overlap (&p->i == &q->j) this would invoke undefined behavior. Than

Re: Undefined behavior due to 6.5.16.1p3

2015-03-10 Thread Robbert Krebbers
On 03/10/2015 05:18 PM, Martin Sebor wrote: I suspect every compiler relies on this requirement in certain cases otherwise copying would require making use of temporary storage. Here's an example: Thanks, this example is indeed not already undefined by effective types, nor 6.2.6.1p6. An entire

Re: Undefined behavior due to 6.5.16.1p3

2015-03-10 Thread Robbert Krebbers
On 03/10/2015 05:44 PM, Robbert Krebbers wrote: On 03/10/2015 05:18 PM, Martin Sebor wrote: I suspect every compiler relies on this requirement in certain cases otherwise copying would require making use of temporary storage. Here's an example: Thanks, this example is indeed not al

Re: Undefined behavior due to 6.5.16.1p3

2015-03-11 Thread Robbert Krebbers
Dear Joseph, On 03/10/2015 11:01 PM, Joseph Myers wrote: and did "u.b.b2 = f (u.a);" instead of "u.b.b2 = u.a;", that would not be undefined (see 6.8.6.4 and GCC PR 43784). Thanks for the references, those are useful! But what about "long long" on 32 bits machines. For example: union { long

Re: Undefined behavior due to 6.5.16.1p3

2015-03-11 Thread Robbert Krebbers
On 03/11/2015 05:31 PM, Vincent Lefevre wrote: I disagree that it is an extension. The standard does not say that "one union member can be active at any time". The interpretation under which this is allowed in confirmed by Note 95 of 6.5.2.3p3. Effective types disallow to access a union member o