Is this a gcc bug?
dewar@gnat.com
dewar@gnat.com
Tue Jan 16 17:06:00 GMT 2001
<<I don't think that even a brilliant optimizer can make any conclusion
about j's value, based on the assumption that j!=4 is the only situation
where the expression is well defined.
>>
On the contrary. The logic goes like this:
1. If j == 4, then the program does undefined things, it can do anything
it wants.
2. The compiler therefore has complete freedom to generate any code it
likes if j==4.
3. One special case of this freedom is that it can generate code that does
the same thing as if j != 4.
4. This is a good choice since it eliminates a test.
So an optimizer can indeed make this assumption, and it is quite difficult
to word an informal standard to avoid this (it may be even harder to word
a formal standard to prevent this).
undefined is a nasty semantic concept :-)
More information about the Gcc
mailing list