On 2018-06-07 16:10:03 +0000, Austin Group Bug Tracker wrote:
> On P567 L19829 (abs), replace<blockquote>If the result cannot be
> represented, the behavior is undefined.</blockquote>with<blockquote><CX>If
> the result cannot be represented, the result shall be
> {INT_MIN}.</CX></blockquote>
> On P567 L19838 (abs), replace<blockquote>In two's-complement
> representation, the absolute value of the negative integer with largest
> magnitude {INT_MIN} might not be
> representable.</blockquote>with<blockquote><CX>Since POSIX.1 requires a
> two's complement representation of <b>int</b>, the absolute value of the
> negative integer with the largest magnitude {INT_MIN} is not representable;
> but the rules of negation in two's complement arithmetic ensure that
> {INT_MIN} is returned.</CX></blockquote>

I completely disagree on this change. Undefined behavior is useful
in order to allow the compiler to optimize, e.g. the compiler should
be allowed to assume that abs(x) >= 0 during VRP. This is also
useful for security: undefined behavior allows the compiler to check
this particular case and trigger a trap, avoiding erratic behavior
of the program.

Ditto for the other similar changes:

> On P1135 L38352 (imaxabs), replace<blockquote>If the result cannot be
> represented, the behavior is undefined.</blockquote>with<blockquote><CX>If
> the result cannot be represented, the result shall be
> {INTMAX_MIN}.</CX></blockquote>
> On P1135 L38361 (imaxabs), replace<blockquote>The absolute value of the
> most negative number cannot be represented in two's
> complement.</blockquote>with<blockquote><CX>Since POSIX.1 requires a two's
> complement representation of <b>intmax_t</b>, the absolute value of the
> negative integer with the largest magnitude {INTMAX_MIN} is not
> representable; but the rules of negation in two's complement arithmetic
> ensure that {INTMAX_MIN} is returned.</CX></blockquote>
>  On P1232 L41185 (labs), replace<blockquote>If the result cannot be
> represented, the behavior is undefined.</blockquote>with<blockquote><CX>If
> the result cannot be represented, the result shall be {LONG_MIN} for
> <i>labs</i>() or {LLONG_MIN} for <i>llabs</i>() .</CX></blockquote>
> On P1232 L41195 (labs APPLICATION USAGE),
> replace<blockquote>None.</blockquote>with<blockquote><CX>Since POSIX.1
> requires a two's complement representation of <b>long</b> and <b>long
> long</b>, the absolute value of the negative integer with the largest
> magnitude {LONG_MIN} or {LLONG_MIN} is not representable; but the rules of
> negation in two's complement arithmetic ensure that {LONG_MIN} (for
> <i>labs()</i>) or {LLONG_MIN} (for <i>llabs()</i>) is
> returned.</CX></blockquote>

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to