Some tests in gcc.c-torture rely on undefined behaviour?
Joe Buck
Joe.Buck@synopsys.COM
Tue Jul 12 16:45:00 GMT 2005
On Tue, Jul 12, 2005 at 09:41:22AM -0500, Nicholas Nethercote wrote:
> I've been looking at the gcc.c-torture tests, it seems some of them rely
> on undefined behaviour. For example, 920612-1.c looks like this:
>
> f(j)int j;{return++j>0;}
> main(){if(f((~0U)>>1))abort();exit(0);}
Wow. It appears that it would be legal for a C compiler to optimize f() to
int f(int j) { return 1;}
since the compiler is entitled to assume that overflow does not occur.
Just the same, I don't think we necessarily want to take advantage of
every degree of freedom the standards give us (at least, not by default).
(Oh, crap; I see a massive thread re-emerging).
More information about the Gcc
mailing list