[binutils-gdb] gas: sframe: simplify get_offset_size_in_bytes
Jens Remus
jremus@sourceware.org
Wed Jan 14 12:26:07 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=18d0fe3ddb9dac96b23b446fbab60f1e6aa39c52
commit 18d0fe3ddb9dac96b23b446fbab60f1e6aa39c52
Author: Jens Remus <jremus@linux.ibm.com>
Date: Wed Jan 14 13:25:21 2026 +0100
gas: sframe: simplify get_offset_size_in_bytes
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>
Diff:
---
gas/gen-sframe.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
index bf5cd62f6fc..f5e0f3792cc 100644
--- a/gas/gen-sframe.c
+++ b/gas/gen-sframe.c
@@ -204,14 +204,14 @@ get_offset_size_in_bytes (offsetT value)
{
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;
}
More information about the Binutils-cvs
mailing list