]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Suppress clang -Wabsolute-value warning on math_check_force_underflow
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 17 Oct 2025 19:12:53 +0000 (16:12 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 21 Oct 2025 12:24:21 +0000 (09:24 -0300)
clang warns:

  ../sysdeps/x86/fpu/powl_helper.c:233:3: error: absolute value function
  '__builtin_fabsf' given an argument of type 'typeof (res)' (aka 'long
  double') but has parameter of type 'float' which may cause truncation of
  value [-Werror,-Wabsolute-value]
    math_check_force_underflow (res);
    ^
  ./math-underflow.h:45:11: note: expanded from macro
  'math_check_force_underflow'
        if (fabs_tg (force_underflow_tmp)                         \
            ^
  ./math-underflow.h:27:20: note: expanded from macro 'fabs_tg'
  #define fabs_tg(x) __MATH_TG ((x), (__typeof (x)) __builtin_fabs, (x))
                     ^
  ../math/math.h:899:16: note: expanded from macro '__MATH_TG'
                 float: FUNC ## f ARGS,           \
                        ^
  <scratch space>:73:1: note: expanded from here
  __builtin_fabsf
  ^

Due the use of _Generic from TG_MATH.

Reviewed-by: Sam James <sam@gentoo.org>
math/math-underflow.h

index faac88098bd987816cd6d63a850a0ff74a89a4a9..dc8736b04eb696d3ab884239ae649d3006610e62 100644 (file)
@@ -23,6 +23,7 @@
 #include <math.h>
 
 #include <math-barriers.h>
+#include <libc-diag.h>
 
 #define fabs_tg(x) __MATH_TG ((x), (__typeof (x)) __builtin_fabs, (x))
 
 #define min_of_type(x) __MATH_TG ((x), (__typeof (x)) min_of_type_, ())
 
 /* If X (which is not a NaN) is subnormal, force an underflow
-   exception.  */
+   exception.
+
+   clang issues a warning where _Generic is using a non expected
+   builtin which may cause truncation of value.
+
+   clang warns the value might be truncated due the use of _Generics. */
 #define math_check_force_underflow(x)                          \
   do                                                           \
     {                                                          \
+      DIAG_PUSH_NEEDS_COMMENT_CLANG;                           \
+      DIAG_IGNORE_NEEDS_COMMENT_CLANG (18, "-Wabsolute-value"); \
       __typeof (x) force_underflow_tmp = (x);                  \
       if (fabs_tg (force_underflow_tmp)                                \
          < min_of_type (force_underflow_tmp))                  \
@@ -49,6 +57,7 @@
            = force_underflow_tmp * force_underflow_tmp;        \
          math_force_eval (force_underflow_tmp2);               \
        }                                                       \
+      DIAG_POP_NEEDS_COMMENT_CLANG;                            \
     }                                                          \
   while (0)
 /* Likewise, but X is also known to be nonnegative.  */