Fix -O1 compilation errors with `__ddivl' and `__fdivl' [BZ #19444]

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Fix -O1 compilation errors with `__ddivl' and `__fdivl' [BZ #19444]

Maciej Rozycki
Complementing commit 4a06ceea33ec ("sysdeps/ieee754/soft-fp: ignore
maybe-uninitialized with -O [BZ #19444]") and commit 27c5e756a2a8
("sysdeps/ieee754: prevent maybe-uninitialized errors with -O [BZ
#19444]") also fix compilation errors observed at -O1 in `__ddivl' and
`__fdivl' with GCC 9 and RISC-V targets:

In file included from ../soft-fp/soft-fp.h:318,
                 from ../sysdeps/ieee754/soft-fp/s_fdivl.c:27:
../sysdeps/ieee754/soft-fp/s_fdivl.c: In function '__fdivl':
../soft-fp/op-2.h:108:9: error: 'R_f1' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  108 |         : (X##_f1 << (2*_FP_W_TYPE_SIZE - (N)))) \
      |         ^
../sysdeps/ieee754/soft-fp/s_fdivl.c:37:14: note: 'R_f1' was declared here
   37 |   FP_DECL_Q (R);
      |              ^
../soft-fp/op-common.h:39:3: note: in expansion of macro '_FP_FRAC_DECL_2'
   39 |   _FP_FRAC_DECL_##wc (X)
      |   ^~~~~~~~~~~~~~
../soft-fp/quad.h:226:24: note: in expansion of macro '_FP_DECL'
  226 | # define FP_DECL_Q(X)  _FP_DECL (2, X)
      |                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_fdivl.c:37:3: note: in expansion of macro 'FP_DECL_Q'
   37 |   FP_DECL_Q (R);
      |   ^~~~~~~~~
../soft-fp/op-2.h:109:8: error: 'R_f0' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  109 |        | X##_f0) != 0));    \
      |        ^
../sysdeps/ieee754/soft-fp/s_fdivl.c:37:14: note: 'R_f0' was declared here
   37 |   FP_DECL_Q (R);
      |              ^
../soft-fp/op-common.h:39:3: note: in expansion of macro '_FP_FRAC_DECL_2'
   39 |   _FP_FRAC_DECL_##wc (X)
      |   ^~~~~~~~~~~~~~
../soft-fp/quad.h:226:24: note: in expansion of macro '_FP_DECL'
  226 | # define FP_DECL_Q(X)  _FP_DECL (2, X)
      |                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_fdivl.c:37:3: note: in expansion of macro 'FP_DECL_Q'
   37 |   FP_DECL_Q (R);
      |   ^~~~~~~~~
In file included from ../soft-fp/soft-fp.h:318,
                 from ../sysdeps/ieee754/soft-fp/s_ddivl.c:31:
../sysdeps/ieee754/soft-fp/s_ddivl.c: In function '__ddivl':
../soft-fp/op-2.h:98:25: error: 'R_f1' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   98 |        X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) \
      |                         ^~
../sysdeps/ieee754/soft-fp/s_ddivl.c:41:14: note: 'R_f1' was declared here
   41 |   FP_DECL_Q (R);
      |              ^
../soft-fp/op-2.h:37:36: note: in definition of macro '_FP_FRAC_DECL_2'
   37 |   _FP_W_TYPE X##_f0 _FP_ZERO_INIT, X##_f1 _FP_ZERO_INIT
      |                                    ^
../soft-fp/quad.h:226:24: note: in expansion of macro '_FP_DECL'
  226 | # define FP_DECL_Q(X)  _FP_DECL (2, X)
      |                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_ddivl.c:41:3: note: in expansion of macro 'FP_DECL_Q'
   41 |   FP_DECL_Q (R);
      |   ^~~~~~~~~
../soft-fp/op-2.h:101:17: error: 'R_f0' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  101 |       : (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \
      |                 ^~
../sysdeps/ieee754/soft-fp/s_ddivl.c:41:14: note: 'R_f0' was declared here
   41 |   FP_DECL_Q (R);
      |              ^
../soft-fp/op-2.h:37:14: note: in definition of macro '_FP_FRAC_DECL_2'
   37 |   _FP_W_TYPE X##_f0 _FP_ZERO_INIT, X##_f1 _FP_ZERO_INIT
      |              ^
../soft-fp/quad.h:226:24: note: in expansion of macro '_FP_DECL'
  226 | # define FP_DECL_Q(X)  _FP_DECL (2, X)
      |                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_ddivl.c:41:3: note: in expansion of macro 'FP_DECL_Q'
   41 |   FP_DECL_Q (R);
      |   ^~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [.../sysd-rules:587: .../math/s_fdivl.o] Error 1
make[2]: *** Waiting for unfinished jobs....
cc1: all warnings being treated as errors
make[2]: *** [.../sysd-rules:587: .../math/s_ddivl.o] Error 1

This comes from cases in _FP_DIV that return a result described as
FP_CLS_ZERO or FP_CLS_INF and do not initialize the fractional part,
which is then operated on unconditionally in FP_TRUNC_COOKED before
being ignored by _FP_PACK_CANONICAL.

Clearly at this optimization level GCC cannot guarantee to be able to
determine that the fractional part is ultimately unused, so ignore the
error as with the earlier commits referred, letting compilation proceed.

        [BZ #19444]
        * sysdeps/ieee754/soft-fp/s_ddivl.c (__ddivl): Ignore errors
        from `-Wmaybe-uninitialized'.
        * sysdeps/ieee754/soft-fp/s_fdivl.c (__fdivl): Likewise.
---
Hi,

 I have verified that the error goes away if the affected FP_CLS_ZERO and
FP_CLS_INF cases have been modified within _FP_DIV such as to initialise
the fractional part, so this is indeed a false alarm, however that causes
code size pessimisation at -O2, so ignoring the errors is indeed the best
what we can do here, as with the previous commits.

 Unfortunately my WDC copyright assignment with FSF, as I have noted with
commit 656dd306d49f ("RISC-V: Fix `test' operand error with soft-float ABI
being configured"), has not been completed yet and I think this change,
combined with the said commit, may be stretching what can be considered a
legally insignificant change, though I note that:

"A regular series of repeated changes, such as renaming a symbol, is not
legally significant even if the symbol has to be renamed in many places."

so perhaps this can be considered a single change applied twice and
therefore still fitting in the limit of roughly 15 lines.

 OK to apply right away then?

  Maciej
---
 sysdeps/ieee754/soft-fp/s_ddivl.c |   12 ++++++++++++
 sysdeps/ieee754/soft-fp/s_fdivl.c |   12 ++++++++++++
 2 files changed, 24 insertions(+)

glibc-soft-fp-xdivl.diff
Index: glibc/sysdeps/ieee754/soft-fp/s_ddivl.c
===================================================================
--- glibc.orig/sysdeps/ieee754/soft-fp/s_ddivl.c
+++ glibc/sysdeps/ieee754/soft-fp/s_ddivl.c
@@ -28,6 +28,16 @@
 #undef f64divf128
 
 #include <math-narrow.h>
+#include <libc-diag.h>
+
+/* R_f[01] are not set in cases where they are not used in packing,
+   but the compiler does not see that they are set in all cases where
+   they are used, resulting in warnings that they may be used
+   uninitialized.  The location of the warning differs in different
+   versions of GCC, it may be where R is defined using a macro or it
+   may be where the macro is defined.  This happens only with -O1.  */
+DIAG_PUSH_NEEDS_COMMENT;
+DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 #include <soft-fp.h>
 #include <double.h>
 #include <quad.h>
@@ -56,4 +66,6 @@ __ddivl (_Float128 x, _Float128 y)
   CHECK_NARROW_DIV (ret, x, y);
   return ret;
 }
+DIAG_POP_NEEDS_COMMENT;
+
 libm_alias_double_ldouble (div)
Index: glibc/sysdeps/ieee754/soft-fp/s_fdivl.c
===================================================================
--- glibc.orig/sysdeps/ieee754/soft-fp/s_fdivl.c
+++ glibc/sysdeps/ieee754/soft-fp/s_fdivl.c
@@ -24,6 +24,16 @@
 #undef f32divf128
 
 #include <math-narrow.h>
+#include <libc-diag.h>
+
+/* R_f[01] are not set in cases where they are not used in packing,
+   but the compiler does not see that they are set in all cases where
+   they are used, resulting in warnings that they may be used
+   uninitialized.  The location of the warning differs in different
+   versions of GCC, it may be where R is defined using a macro or it
+   may be where the macro is defined.  This happens only with -O1.  */
+DIAG_PUSH_NEEDS_COMMENT;
+DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 #include <soft-fp.h>
 #include <single.h>
 #include <quad.h>
@@ -52,4 +62,6 @@ __fdivl (_Float128 x, _Float128 y)
   CHECK_NARROW_DIV (ret, x, y);
   return ret;
 }
+DIAG_POP_NEEDS_COMMENT;
+
 libm_alias_float_ldouble (div)
Reply | Threaded
Open this post in threaded view
|

[PING][PATCH] Fix -O1 compilation errors with `__ddivl' and `__fdivl' [BZ #19444]

Maciej Rozycki
On Thu, 11 Apr 2019, Maciej W. Rozycki wrote:

> [BZ #19444]
> * sysdeps/ieee754/soft-fp/s_ddivl.c (__ddivl): Ignore errors
> from `-Wmaybe-uninitialized'.
> * sysdeps/ieee754/soft-fp/s_fdivl.c (__fdivl): Likewise.

 Ping for <https://sourceware.org/ml/libc-alpha/2019-04/msg00286.html>.

  Maciej
Reply | Threaded
Open this post in threaded view
|

Re: [PING][PATCH] Fix -O1 compilation errors with `__ddivl' and `__fdivl' [BZ #19444]

Joseph Myers
On Wed, 24 Apr 2019, Maciej Rozycki wrote:

> On Thu, 11 Apr 2019, Maciej W. Rozycki wrote:
>
> > [BZ #19444]
> > * sysdeps/ieee754/soft-fp/s_ddivl.c (__ddivl): Ignore errors
> > from `-Wmaybe-uninitialized'.
> > * sysdeps/ieee754/soft-fp/s_fdivl.c (__fdivl): Likewise.
>
>  Ping for <https://sourceware.org/ml/libc-alpha/2019-04/msg00286.html>.

This patch is OK.

--
Joseph S. Myers
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [PING][PATCH] Fix -O1 compilation errors with `__ddivl' and `__fdivl' [BZ #19444]

Maciej Rozycki
On Mon, 29 Apr 2019, Joseph Myers wrote:

> > > [BZ #19444]
> > > * sysdeps/ieee754/soft-fp/s_ddivl.c (__ddivl): Ignore errors
> > > from `-Wmaybe-uninitialized'.
> > > * sysdeps/ieee754/soft-fp/s_fdivl.c (__fdivl): Likewise.
> >
> >  Ping for <https://sourceware.org/ml/libc-alpha/2019-04/msg00286.html>.
>
> This patch is OK.

 I have committed this change now, thanks for your review.

  Maciej