]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: fix Wshift-overflow warning.
authorCollin Funk <collin.funk1@gmail.com>
Mon, 22 Sep 2025 05:25:46 +0000 (22:25 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Fri, 3 Oct 2025 01:01:23 +0000 (18:01 -0700)
When compiling on x86_64 with -Wshift-overflow=2 you can see the
following warning:

../sysdeps/ieee754/flt-32/math_config.h: In function ‘is_inf’:
../sysdeps/ieee754/flt-32/math_config.h:184:37: warning: result of ‘2139095040 << 1’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Wshift-overflow=]
  184 |   return (x << 1) == (EXPONENT_MASK << 1);
      |                                     ^~

This patch adjusts the definitions to use UINT32_C. This matches the
definitions in sysdeps/ieee754/dbl-64/math_config.h which use UINT64_C
for these definitions.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
sysdeps/ieee754/flt-32/math_config.h

index 33ea631d5f484546f9df11d9df4105922cbf406f..6bb5c3324cc3a0df1e41ee2d2b840d9df679a53b 100644 (file)
@@ -166,11 +166,11 @@ issignalingf_inline (float x)
 #define MANTISSA_WIDTH  23
 #define EXPONENT_WIDTH  8
 #define EXPONENT_BIAS   127
-#define MANTISSA_MASK   0x007fffff
-#define EXPONENT_MASK   0x7f800000
-#define EXP_MANT_MASK   0x7fffffff
-#define QUIET_NAN_MASK  0x00400000
-#define SIGN_MASK       0x80000000
+#define MANTISSA_MASK   UINT32_C (0x007fffff)
+#define EXPONENT_MASK   UINT32_C (0x7f800000)
+#define EXP_MANT_MASK   UINT32_C (0x7fffffff)
+#define QUIET_NAN_MASK  UINT32_C (0x00400000)
+#define SIGN_MASK       UINT32_C (0x80000000)
 
 static inline bool
 is_nan (uint32_t x)