]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Avoid maybe-uninitialized warning in __kernel_rem_pio2
authorAndreas Schwab <schwab@suse.de>
Sun, 8 Oct 2023 16:23:30 +0000 (18:23 +0200)
committerAndreas Schwab <schwab@suse.de>
Mon, 16 Oct 2023 07:59:32 +0000 (09:59 +0200)
With GCC 14 on 32-bit x86 the compiler emits a maybe-uninitialized
warning:

../sysdeps/ieee754/dbl-64/k_rem_pio2.c: In function '__kernel_rem_pio2':
../sysdeps/ieee754/dbl-64/k_rem_pio2.c:364:20: error: 'fq' may be used uninitialized [-Werror=maybe-uninitialized]
  364 |           y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
      |                  ~~^~~

This is similar to the warning that is suppressed in the other branch of
the switch.  Help the compiler knowing that the variable is always
initialized, which also makes the suppression obsolete.

sysdeps/ieee754/dbl-64/k_rem_pio2.c

index 6e2ef5d07bade489a6b8a0d7da343ce7e334bfaf..f75392525c200160938eacdb758f5b799a7882b4 100644 (file)
@@ -300,6 +300,11 @@ recompute:
        iq[jz] = (int32_t) z;
     }
 
+  /* jz is always nonnegative here, because the result is never zero to
+     full precision (this function is not called for zero arguments).
+     Help the compiler to know it.  */
+  if (jz < 0) __builtin_unreachable ();
+
   /* convert integer "bit" chunk to floating-point value */
   fw = __scalbn (one, q0);
   for (i = jz; i >= 0; i--)
@@ -330,16 +335,7 @@ recompute:
       for (i = jz; i >= 0; i--)
        fv = math_narrow_eval (fv + fq[i]);
       y[0] = (ih == 0) ? fv : -fv;
-      /* GCC mainline (to be GCC 9), as of 2018-05-22 on i686, warns
-        that fq[0] may be used uninitialized.  This is not possible
-        because jz is always nonnegative when the above loop
-        initializing fq is executed, because the result is never zero
-        to full precision (this function is not called for zero
-        arguments).  */
-      DIAG_PUSH_NEEDS_COMMENT;
-      DIAG_IGNORE_NEEDS_COMMENT (9, "-Wmaybe-uninitialized");
       fv = math_narrow_eval (fq[0] - fv);
-      DIAG_POP_NEEDS_COMMENT;
       for (i = 1; i <= jz; i++)
        fv = math_narrow_eval (fv + fq[i]);
       y[1] = (ih == 0) ? fv : -fv;