]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: sframe: use standard min/max integer constants
authorJens Remus <jremus@linux.ibm.com>
Tue, 13 Jan 2026 12:17:49 +0000 (13:17 +0100)
committerJens Remus <jremus@linux.ibm.com>
Tue, 13 Jan 2026 12:17:49 +0000 (13:17 +0100)
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>
gas/gen-sframe.c

index 4a70ae13ff5b03b8d540b0a0dfca868f97894e4f..b4e983957a1d7ee8776e930a8b0e73e5399f1c80 100644 (file)
@@ -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;