This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is this a gcc bug?


<<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 :-)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]