From: Adhemerval Zanella Date: Wed, 7 May 2025 15:59:59 +0000 (+0000) Subject: math: Fix UB in roundevenf_finite X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00411d0fad301f917610a17ebfd5d1408615cbdb;p=thirdparty%2Fglibc.git math: Fix UB in roundevenf_finite On powerpc64le tanf tests show: UBSAN: Undefined behaviour in ../sysdeps/ieee754/flt-32/math_config.h:105:11 passing zero to __builtin_ctz() --- diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h index fd9481a016..264fb1a162 100644 --- a/sysdeps/ieee754/flt-32/math_config.h +++ b/sysdeps/ieee754/flt-32/math_config.h @@ -23,6 +23,7 @@ #include #include #include +#include #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;