public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid maybe-uninitialized warning in __kernel_rem_pio2
@ 2023-10-09  8:17 Andreas Schwab
  2023-10-13 13:06 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2023-10-09  8:17 UTC (permalink / raw)
  To: libc-alpha

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 | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/sysdeps/ieee754/dbl-64/k_rem_pio2.c b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
index 6e2ef5d07b..af29685c68 100644
--- a/sysdeps/ieee754/dbl-64/k_rem_pio2.c
+++ b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
@@ -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;
-- 
2.42.0


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Avoid maybe-uninitialized warning in __kernel_rem_pio2
  2023-10-09  8:17 [PATCH] Avoid maybe-uninitialized warning in __kernel_rem_pio2 Andreas Schwab
@ 2023-10-13 13:06 ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella Netto @ 2023-10-13 13:06 UTC (permalink / raw)
  To: Andreas Schwab, libc-alpha



On 09/10/23 05:17, Andreas Schwab wrote:
> 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  sysdeps/ieee754/dbl-64/k_rem_pio2.c | 14 +++++---------
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/sysdeps/ieee754/dbl-64/k_rem_pio2.c b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
> index 6e2ef5d07b..af29685c68 100644
> --- a/sysdeps/ieee754/dbl-64/k_rem_pio2.c
> +++ b/sysdeps/ieee754/dbl-64/k_rem_pio2.c
> @@ -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

I think it should double space here.

> +     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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-13 13:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09  8:17 [PATCH] Avoid maybe-uninitialized warning in __kernel_rem_pio2 Andreas Schwab
2023-10-13 13:06 ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).