[llvm-commits] [PATCH] Fix various instances of undefined behavior

Ahmed Charles ahmedcharles at gmail.com
Wed Oct 12 22:59:09 PDT 2011


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Fix-undefined-behavior.patch
Type: application/octet-stream
Size: 4822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111012/70e0e5e8/attachment.obj>


More information about the llvm-commits mailing list