[llvm-commits] [PATCH] Fix various instances of undefined behavior
Eli Friedman
eli.friedman at gmail.com
Thu Oct 13 16:52:32 PDT 2011
On Wed, Oct 12, 2011 at 10:59 PM, Ahmed Charles <ahmedcharles at gmail.com> wrote:
> On Wed, Oct 12, 2011 at 5:27 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> On Wed, Oct 12, 2011 at 4:37 PM, Ahmed Charles <ahmedcharles at gmail.com> wrote:
>>> FDIS 5.6/4 suggests that floating point isn't special:
>>>
>>> The binary / operator yields the quotient, and the binary % operator
>>> yields the remainder from the division of the first expression by the
>>> second. If the second operand of / or % is zero the behavior is
>>> undefined. For integral operands the / operator yields the algebraic
>>> quotient with any fractional part discarded;[81] if the quotient a/b
>>> is representable in the type of the result, (a/b)*b + a%b is equal to
>>> a.
>>>
>>> 81) This is often called truncation towards zero.
>>>
>>> Is there somewhere else that gives floating point different semantics?
>>
>> The IEEE floating-point standard explicitly defines the result of
>> division by zero.
>>
>
> That is true, though the C++ standard doesn't require IEEE 754 (aka
> IEC 559), though it does place requirements on implementations which
> choose to use IEEE 754, but one of those doesn't seem to be whether
> division by zero is undefined.
>
> This could be perfectly benign on all platforms we care about, but
> it's in this patch, if you wish to submit it.
>
> This patch passes make check-all and selfhosting.
Applied everything except the ProfileEstimatorPass.cpp bits. For the
ProfileEstimatorPass.cpp pieces, the code probably isn't doing the
right thing, but I'm having trouble following what it is actually
trying to do.
-Eli
More information about the llvm-commits
mailing list