Martin v. Löwis added the comment:

> "x+1 > x" and "v >= &array[0]" are not the same checks. 
> In the first test, x is used in both parts. I don't understand.

The consequences of "undefined behavior" are really difficult to understand, it 
seems. A compiler which evaluates both relational expressions unconditionally 
to true would be conforming to the C language definition. The reason for that 
has been said several times before, but let me repeat them.

Mathematically, x+1 > x for any real number, so it seems natural to assume that 
this can be determined to be "true" statically. However, what if x+1 overflows? 
Shouldn't then it evaluate to "false"? Not necessarily if x is signed. Then the 
behavior of overflow is undefined, and *any* result of the comparison would be 
conforming to the standard: the overflow may trap, the expression may evaluate 
to "false", or the expression may evaluate to "true", or your hard disk may get 
erased - all of these would be conforming to the C language definition.

For v >= &array[0], this is the same issue. If v points into the array, the 
expression is true. If v doesn't point into the array, the behavior is 
undefined, so the compiler may chose to give false, or to give true, or to 
actually compare the pointers as integers, or to erase your hard disk.

Of these possible behaviors, only two are plausible. For x+1>x, it may be that 
the compiler actually generates code to perform the addition and the 
comparison, or it may statically decide that the expression is always true. For 
v > &array[0], the compiler may either generate code to perform the comparison, 
or statically decide that the expression is true. Either implementation would 
be correct - it's not that the compiler is optimizing "incorrectly".

In the specific case, a compiler might infer that _PyLong_IS_SMALL_INT is 
always true, which would give incorrect results in Python. However, it is the 
patch which is incorrect, not the compiler.

I recommend to close the issue as rejected.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10044>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to