This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is this a gcc bug?
- To: dewar at gnat dot com, eager at mvista dot com
- Subject: Re: Is this a gcc bug?
- From: dewar at gnat dot com
- Date: Tue, 16 Jan 2001 20:06:29 -0500 (EST)
- Cc: Anshil at gmx dot net, aoliva at redhat dot com, gcc at gcc dot gnu dot org
<<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 :-)