Type offsetT is either defined as signed 32-bit or 64-bit integer
depending on whether BFD64 is defined. Do not test for whether an
offsetT value exceeds INT32_MIN..INT32_MAX for !BFD64 32-bit offsetT
(or INT64_MIN..INT64_MAX for BFD64 64-bit offsetT). This is always
true and may result in a compile error when using compiler option
-Werror=type-limits, such as the one resolved with commit
6b8fb74a9403 ("gas: sframe: do not test whether offsetT exceeds
INT64_MIN..INT64_MAX") for BFD64 64-bit offsetT:
../../binutils-gdb/gas/gen-sframe.c: In function ‘get_offset_size_in_bytes’:
../../binutils-gdb/gas/gen-sframe.c:213:45: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
../../binutils-gdb/gas/gen-sframe.c:213:67: error: comparison is always true due to limited range of data type [-Werror=type-limits]
213 | else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
| ^~
Instead of testing for whether the value is in range of
INT8_MIN..INT8_MAX, INT16_MIN..INT16_MAX, or INT32_MIN..INT32_MAX,
test whether the value is unchanged when casted to int8_t, int16_t,
or int32_t. This also improves readability.
gas/
* gen-sframe.c (get_offset_size_in_bytes): Simplify. Do not
test whether !BFD64 32-bit offsetT exceeds INT32_MIN..INT32_MAX.
Fixes: 58008ed4e6af ("gas: sframe: use standard min/max integer constants")
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
{
unsigned int size = 0;
- if (value <= INT8_MAX && value >= INT8_MIN)
+ if (value == (int8_t)value)
size = 1;
- else if (value <= INT16_MAX && value >= INT16_MIN)
+ else if (value == (int16_t)value)
size = 2;
- else if (value <= INT32_MAX && value >= INT32_MIN)
+ else if (value == (int32_t)value)
size = 4;
- else if (sizeof (offsetT) > 4)
- size = 8;
+ else
+ return 8;
return size;
}