Optimisations and undefined behaviour
Richard Earnshaw
Richard.Earnshaw@foss.arm.com
Mon Nov 9 15:05:00 GMT 2015
On 09/11/15 15:00, Andrew Haley wrote:
> On 11/09/2015 02:56 PM, Richard Earnshaw wrote:
>> On 09/11/15 14:29, Andrew Haley wrote:
>
>>> Here it is again:
>>>
>>> int foo(int x) {
>>> if (x > 1290) {
>>> printf("X is wrong here %d, but we don't care\n", x);
>>> }
>>> return x*x*x;
>>>
>>> Here, the printf writes to a stream then the UB happens.
>>
>> Not if setvbuf has been used to make the stream unbuffered.
>
> It hasn't. And I know it hasn't because it's my example.
>
A compiler would still need to do whole-program analysis to prove that;
it can't work on the assumption that it hasn't been done.
> And besides, the UB might cause the computer to crash before the data
> has been written to stdout by the kernel; the same reasoning applies.
>
> Andrew.
>
UB that causes the machine to crash is, I think, outside of what we need
to think about. Any machine that's falls over in that case is not
interesting.
R.
More information about the Gcc-help
mailing list