basic VRP min/max range overflow question

Robert Dewar dewar@adacore.com
Mon Jun 20 13:14:00 GMT 2005


Paul Schlie wrote:

>>There don't need to be examples. The as-if rule always applies, if you cannot
>>write a legitimate C program that shows the difference between two possible
>>implementations, then both are correct.
> 
> 
> ??? as-if means they're logically equivalent (i.e. there is no logical
> difference between the two alternative representations, and strongly support
> that this should be the guideline for all optimizations).

as if means what I said in the above quoted paragraph. I do not know what
"no logical difference" means if it is different from the above criterion.
> 
> 
>>                                               Note that the requirement of a
>>legitimate C program exlude ANY program which has undefined behavior anywhere.
> 
> 
> Then it is illegitimate for a compiler to generate a program which contains
> a known undefined behavior, (i.e. any known overflow, any unsigned to signed
> cast which is known to not be representable, any pointer dereference of a
> known null value, etc.; rather than generate any code.)

No, that's plain untrue, I don't know how you got that idea.

> Expression reordering does not necessitate the violation of sequence point
> semantics as long as at the last point of reordering, the resulting
> semantics are logically equivalent (as-if); which is why it's a safe
> optimization if the logical behavior is preserved.

Again, as-if behavior means that it is not possible to write a correct
C program that distinguishes the cases. No program containing an overflow
can be used for such a test.
> 




More information about the Gcc mailing list