]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in roundevenf_finite
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 15:59:59 +0000 (15:59 +0000)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:34:15 +0000 (09:34 -0300)
On powerpc64le tanf tests show:

UBSAN: Undefined behaviour in ../sysdeps/ieee754/flt-32/math_config.h:105:11 passing zero to __builtin_ctz()

sysdeps/ieee754/flt-32/math_config.h

index fd9481a01689a5b3ca10dd243f29b619c2166984..264fb1a162fde9ab186e28129fc9884733a15165 100644 (file)
@@ -23,6 +23,7 @@
 #include <math_private.h>
 #include <nan-high-order-bit.h>
 #include <stdint.h>
+#include <stdbit.h>
 
 #ifndef WANT_ROUNDING
 /* Correct special case results in non-nearest rounding modes.  */
@@ -102,7 +103,7 @@ roundevenf_finite (float x)
     {
       union { float f; uint32_t i; } u = {y};
       union { float f; uint32_t i; } v = {y - copysignf (1.0, x)};
-      if (__builtin_ctzl (v.i) > __builtin_ctzl (u.i))
+      if (stdc_leading_zeros (v.i) > stdc_leading_zeros (u.i))
         y = v.f;
     }
   return y;