[PATCH v2] gas: sframe: use standard min/max integer constants
Indu Bhagat
indu.bhagat@oracle.com
Tue Jan 13 10:03:07 GMT 2026
On 1/9/26 3:26 AM, Jens Remus wrote:
> Replace the use of custom VALUE_{8|16|32|64}BIT constant definitions
> with the standard INT{8|16|32|64}_{MIN|MAX} ones from stdint.h.
>
> Besides improving readability this also fixes the issue that the
> smallest representable signed 8/16/32-bit integer value was
> erroneously sized as the next larger integer type. For example
> get_offset_size_in_bytes (INT8_MIN) returned 2 instead of 1, due
> to INT8_MIN (= -128) != -VALUE_8BIT (= -127):
>
> (gdb) call get_offset_size_in_bytes (-127)
> $1 = 1
> (gdb) call get_offset_size_in_bytes (-128)
> $2 = 2
>
> gas/
> * gen-sframe.c (VALUE_8BIT, VALUE_16BIT, VALUE_32BIT,
> VALUE_64BIT): Remove.
> (get_offset_size_in_bytes): Use standard min/max integer
> constants.
>
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
LGTM.
> ---
>
> Notes (jremus):
> Changes in v2:
> - Reword commit message to mention bug fix. (Jens)
>
> gas/gen-sframe.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c
> index 4a70ae13ff5b..b4e983957a1d 100644
> --- a/gas/gen-sframe.c
> +++ b/gas/gen-sframe.c
> @@ -197,15 +197,6 @@ sframe_fre_set_fp_track (struct sframe_row_entry *fre, offsetT fp_offset)
> fre->merge_candidate = false;
> }
>
> -/* All stack offset values within an FRE are uniformly encoded in the same
> - number of bytes. The size of the stack offset values will, however, vary
> - across FREs. */
> -
> -#define VALUE_8BIT 0x7f
> -#define VALUE_16BIT 0x7fff
> -#define VALUE_32BIT 0x7fffffff
> -#define VALUE_64BIT 0x7fffffffffffffff
> -
> /* Given a signed offset, return the size in bytes needed to represent it. */
>
> static unsigned int
> @@ -213,14 +204,13 @@ get_offset_size_in_bytes (offsetT value)
> {
> unsigned int size = 0;
>
> - if (value <= VALUE_8BIT && value >= (offsetT) -VALUE_8BIT)
> + if (value <= INT8_MAX && value >= INT8_MIN)
> size = 1;
> - else if (value <= VALUE_16BIT && value >= (offsetT) -VALUE_16BIT)
> + else if (value <= INT16_MAX && value >= INT16_MIN)
> size = 2;
> - else if (value <= VALUE_32BIT && value >= (offsetT) -VALUE_32BIT)
> + else if (value <= INT32_MAX && value >= INT32_MIN)
> size = 4;
> - else if ((sizeof (offsetT) > 4) && (value <= (offsetT) VALUE_64BIT
> - && value >= (offsetT) -VALUE_64BIT))
> + else if ((sizeof (offsetT) > 4) && (value <= INT64_MAX && value >= INT64_MIN))
> size = 8;
>
> return size;
More information about the Binutils
mailing list