[Bug c/56956] ftrapv traps on valid abs-like code
jasonwucj at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Apr 15 04:18:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56956
--- Comment #4 from Chung-Ju Wu <jasonwucj at gmail dot com> 2013-04-15 04:18:13 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > I think 'x' can not present negative value.
>
> The unary minus operator is defined for unsigned types. It doesn't produce
> signed overflow.
According to C99 6.5.3.3 Point 3 and C99 6.5 Point 5:
"The result of the unary '-' operator is the negative of its operand."
"... if the result is ... not in the range of representable
values for its type... the behavior is undefined."
So my understanding is that the evaluation expression '-x' is not
a representable value of 'uint64_t', which is undefined behavior,
resulting abort if -ftrav is issued.
Perhaps my understanding is incorrect? :(
More information about the Gcc-bugs
mailing list