Patchwork [2/2] soft-fp: ignore maybe-uninitialized

login
register
mail settings
Submitter Martin Jansa
Date Sept. 19, 2018, 10:08 a.m.
Message ID <20180919100825.22999-2-Martin.Jansa@gmail.com>
Download mbox | patch
Permalink /patch/29464/
State New
Headers show

Comments

Martin Jansa - Sept. 19, 2018, 10:08 a.m.
* with -O it fails with:

In file included from ../soft-fp/soft-fp.h:318,
                 from ../sysdeps/ieee754/soft-fp/s_fdiv.c:28:
../sysdeps/ieee754/soft-fp/s_fdiv.c: In function '__fdiv':
../soft-fp/op-2.h:98:25: error: 'R_f1' may be used uninitialized in this function [-Werror=maybe-uninitialized]
        X##_f0 = (X##_f1 << (_FP_W_TYPE_SIZE - (N)) | X##_f0 >> (N) \
                         ^~
../sysdeps/ieee754/soft-fp/s_fdiv.c:38:14: note: 'R_f1' was declared here
   FP_DECL_D (R);
              ^
../soft-fp/op-2.h:37:36: note: in definition of macro '_FP_FRAC_DECL_2'
   _FP_W_TYPE X##_f0 _FP_ZERO_INIT, X##_f1 _FP_ZERO_INIT
                                    ^
../soft-fp/double.h:95:24: note: in expansion of macro '_FP_DECL'
 # define FP_DECL_D(X)  _FP_DECL (2, X)
                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_fdiv.c:38:3: note: in expansion of macro 'FP_DECL_D'
   FP_DECL_D (R);
   ^~~~~~~~~
../soft-fp/op-2.h:101:17: error: 'R_f0' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       : (X##_f0 << (_FP_W_TYPE_SIZE - (N))) != 0)); \
                 ^~
../sysdeps/ieee754/soft-fp/s_fdiv.c:38:14: note: 'R_f0' was declared here
   FP_DECL_D (R);
              ^
../soft-fp/op-2.h:37:14: note: in definition of macro '_FP_FRAC_DECL_2'
   _FP_W_TYPE X##_f0 _FP_ZERO_INIT, X##_f1 _FP_ZERO_INIT
              ^
../soft-fp/double.h:95:24: note: in expansion of macro '_FP_DECL'
 # define FP_DECL_D(X)  _FP_DECL (2, X)
                        ^~~~~~~~
../sysdeps/ieee754/soft-fp/s_fdiv.c:38:3: note: in expansion of macro 'FP_DECL_D'
   FP_DECL_D (R);
   ^~~~~~~~~

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 soft-fp/op-2.h | 3 +++
 1 file changed, 3 insertions(+)
Joseph Myers - Sept. 19, 2018, 1:28 p.m.
On Wed, 19 Sep 2018, Martin Jansa wrote:

> diff --git a/soft-fp/op-2.h b/soft-fp/op-2.h
> index 6020d663d4..6672337949 100644
> --- a/soft-fp/op-2.h
> +++ b/soft-fp/op-2.h
> @@ -92,6 +92,8 @@
>  	      X##_f1 = 0;						\
>  	    }))
>  
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

As soft-fp is shared with libgcc, it can't use the DIAG_* macros from 
libc-diag.h.  *But* the principle of needing detailed comments to justify 
any warning suppression remains.  Those comments would need to identify 
the warning in question, and why it is a false positive, and the most 
recent compiler version known to produce that false positive, and the 
suppression should probably be conditional on building with -O if it isn't 
needed with -O2 / -Os.

Rather than putting the suppression around a macro definition, I wonder 
about putting it at the place where the macros are used (s_fdiv.c, it 
appears from the warnings you quote).  That's what we do for the soft-fp 
implementations of fma, for example, and it would allow you to use the 
DIAG_* macros.  You'd need to add DIAG_IGNORE_O1_NEEDS_COMMENT like 
DIAG_IGNORE_Os_NEEDS_COMMENT to libc-diag.h, and then use it with an 
appropriate comment in s_fdiv.c (explaining the warning and why it is a 
false positive).

Patch

diff --git a/soft-fp/op-2.h b/soft-fp/op-2.h
index 6020d663d4..6672337949 100644
--- a/soft-fp/op-2.h
+++ b/soft-fp/op-2.h
@@ -92,6 +92,8 @@ 
 	      X##_f1 = 0;						\
 	    }))
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #define _FP_FRAC_SRS_2(X, N, sz)					\
   (void) (((N) < _FP_W_TYPE_SIZE)					\
 	  ? ({								\
@@ -109,6 +111,7 @@ 
 			    | X##_f0) != 0));				\
 	      X##_f1 = 0;						\
 	    }))
+#pragma GCC diagnostic pop
 
 #define _FP_FRAC_ADDI_2(X, I)	\
   __FP_FRAC_ADDI_2 (X##_f1, X##_f0, I)