This is the mail archive of the
mailing list for the GCC project.
Warning for converting (possibly) negative float/double to unsigned int
- From: Bradley Lucier <lucier at math dot purdue dot edu>
- To: gcc at gcc dot gnu dot org
- Cc: Bradley Lucier <lucier at math dot purdue dot edu>
- Date: Fri, 26 Feb 2016 16:28:10 -0500
- Subject: Warning for converting (possibly) negative float/double to unsigned int
- Authentication-results: sourceware.org; auth=none
Perhaps this question is appropriate for the gcc mail list.
Converting a float/double to unsigned int is undefined if the result
would be negative when converted to a signed int.
x86-64 and arm treat this condition differently---x86-64 returns a value
whose bit pattern is the same as the bit pattern for converting to
signed int, and arm returns zero. So it would be nice to have a warning
that this will (or could) happen.
I couldn't find such a warning in the GCC manual or in the GCC code
base. Looking through the code, it seemed it might go in this code in
force_operand() in expr.c on mainline:
if (UNARY_P (value))
target = gen_reg_rtx (GET_MODE (value));
op1 = force_operand (XEXP (value, 0), NULL_RTX);
convert_move (target, op1, code == ZERO_EXTEND);
expand_fix (target, op1, code == UNSIGNED_FIX);
expand_float (target, op1, code == UNSIGNED_FLOAT);
return expand_simple_unop (GET_MODE (value), code, op1,
But maybe not.
Any advice on how to proceed? I'd be willing to write and test the few
lines of code myself if I knew where to put them.