[1/2] sysdeps/ieee754: prevent maybe-uninitialized errors

Message ID 20180919100825.22999-1-Martin.Jansa@gmail.com
State New
Headers show
Series
  • [1/2] sysdeps/ieee754: prevent maybe-uninitialized errors
Related show

Commit Message

Martin Jansa Sept. 19, 2018, 10:08 a.m.
* with -O included in CFLAGS it fails to build with:

../sysdeps/ieee754/ldbl-96/e_jnl.c: In function '__ieee754_jnl':
../sysdeps/ieee754/ldbl-96/e_jnl.c:146:20: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      b = invsqrtpi * temp / sqrtl (x);
          ~~~~~~~~~~^~~~~~
../sysdeps/ieee754/ldbl-96/e_jnl.c: In function '__ieee754_ynl':
../sysdeps/ieee754/ldbl-96/e_jnl.c:375:16: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  b = invsqrtpi * temp / sqrtl (x);
      ~~~~~~~~~~^~~~~~

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 sysdeps/ieee754/dbl-64/e_jn.c    | 2 ++
 sysdeps/ieee754/ldbl-128/e_jnl.c | 4 ++++
 sysdeps/ieee754/ldbl-96/e_jnl.c  | 4 ++++
 3 files changed, 10 insertions(+)

Comments

Joseph Myers Sept. 19, 2018, 1:22 p.m. | #1
On Wed, 19 Sep 2018, Martin Jansa wrote:

> * with -O included in CFLAGS it fails to build with:

This is bug 19444, so [BZ #19444] in ChangeLog entries for it.  (If your 
patch only fixes some of the issues building with -O, your commit message 
needs to make it clear, so that it's obvious whether the bug should be 
resolved as FIXED with target milestone set to the first mainline release 
with the fix immediately after commit.  But the bug number should be given 
even for changes only fixing part of a bug - they just need to make clear 
whether they are complete or partial fixes.)

> +	      default: temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]

We don't use // comments in glibc code.  We also don't add initializers / 
assignments that might generate code just to silence warnings; if the code 
cannot be written in a way that makes it clear to the compiler what is / 
is not uninitialized, without resulting in extra generated code, we use 
the DIAG_* macros from libc-diag.h, with appropriate comments in every 
case explaining why in fact the warning is a false positive, to silence 
the warnings locally.

Unfortunately <https://sourceware.org/glibc/wiki/Style_and_Conventions> 
doesn't mention either of these conventions, so there is clearly scope for 
us to improve our documentation on contributing to glibc.

Patch

diff --git a/sysdeps/ieee754/dbl-64/e_jn.c b/sysdeps/ieee754/dbl-64/e_jn.c
index cb7c6cf266..e9964311ca 100644
--- a/sysdeps/ieee754/dbl-64/e_jn.c
+++ b/sysdeps/ieee754/dbl-64/e_jn.c
@@ -109,6 +109,7 @@  __ieee754_jn (int n, double x)
 	      case 1: temp = -c + s; break;
 	      case 2: temp = -c - s; break;
 	      case 3: temp = c - s; break;
+	      default: temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	      }
 	    b = invsqrtpi * temp / sqrt (x);
 	  }
@@ -316,6 +317,7 @@  __ieee754_yn (int n, double x)
 	  case 1: temp = -s - c; break;
 	  case 2: temp = -s + c; break;
 	  case 3: temp = s + c; break;
+	  default: temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	  }
 	b = invsqrtpi * temp / sqrt (x);
       }
diff --git a/sysdeps/ieee754/ldbl-128/e_jnl.c b/sysdeps/ieee754/ldbl-128/e_jnl.c
index 540b95ca58..2270522e24 100644
--- a/sysdeps/ieee754/ldbl-128/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-128/e_jnl.c
@@ -150,6 +150,8 @@  __ieee754_jnl (int n, _Float128 x)
 	      case 3:
 		temp = c - s;
 		break;
+	      default:
+	        temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	      }
 	    b = invsqrtpi * temp / sqrtl (x);
 	  }
@@ -386,6 +388,8 @@  __ieee754_ynl (int n, _Float128 x)
 	  case 3:
 	    temp = s + c;
 	    break;
+	  default:
+	    temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	  }
 	b = invsqrtpi * temp / sqrtl (x);
       }
diff --git a/sysdeps/ieee754/ldbl-96/e_jnl.c b/sysdeps/ieee754/ldbl-96/e_jnl.c
index fd28f6ae91..ee158cf39a 100644
--- a/sysdeps/ieee754/ldbl-96/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-96/e_jnl.c
@@ -143,6 +143,8 @@  __ieee754_jnl (int n, long double x)
 	      case 3:
 		temp = c - s;
 		break;
+	      default:
+	        temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	      }
 	    b = invsqrtpi * temp / sqrtl (x);
 	  }
@@ -372,6 +374,8 @@  __ieee754_ynl (int n, long double x)
 	  case 3:
 	    temp = s + c;
 	    break;
+	  default:
+	    temp = 0; // just to prevent error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 	  }
 	b = invsqrtpi * temp / sqrtl (x);
       }