Re: Optimisations and undefined behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 08/11/15 19:34, Segher Boessenkool wrote:
> The compiler is free to transform it to
> 
> int foo(int x) {
> 	int t = x*x*x;
> 	if (x > 1290) {
> 		printf("X is wrong here %d, but we don't care\n", x);
> 	}
> 	return t;
> }
> 
> because x*x*x does not have any observable behaviour, and then it is
> obvious it _can_ remove the printf and conditional.

Yes, that is correct.  And, indeed, the hardware is free to do taht
too.  With speculative execution, the "as if" rule is not limited to
the compiler.

Andrew.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux