aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/glibc/glibc/0031-sysdeps-ieee754-prevent-maybe-uninitialized-errors-w.patch
blob: 61f55d4f83d49845c7f91a6cda28db06d8753e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
From 546b46c309a52ed74dc906114b1e984bb9703d74 Mon Sep 17 00:00:00 2001
From: Martin Jansa <Martin.Jansa@gmail.com>
Date: Fri, 14 Sep 2018 23:23:03 +0000
Subject: [PATCH] sysdeps/ieee754: prevent maybe-uninitialized errors with -O
 [BZ #19444]

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);
      ~~~~~~~~~~^~~~~~
../sysdeps/ieee754/dbl-64/e_jn.c: In function '__ieee754_jn':
../sysdeps/ieee754/dbl-64/e_jn.c:113:20: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      b = invsqrtpi * temp / sqrt (x);
          ~~~~~~~~~~^~~~~~
../sysdeps/ieee754/dbl-64/e_jn.c: In function '__ieee754_yn':
../sysdeps/ieee754/dbl-64/e_jn.c:320:16: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  b = invsqrtpi * temp / sqrt (x);
      ~~~~~~~~~~^~~~~~

Build tested with Yocto for ARM, AARCH64, X86, X86_64, PPC, MIPS, MIPS64
with -O, -O1, -Os.
For soft-fp ARM it needs one more fix for -O1:
https://sourceware.org/ml/libc-alpha/2018-09/msg00300.html
For AARCH64 it needs one more fix in locale for -Os.

        [BZ #23716]
        * sysdeps/ieee754/dbl-96/e_jnl.c: Fix build with -O
        * sysdeps/ieee754/ldbl-96/e_jnl.c: Likewise.
        * sysdeps/ieee754/ldbl-128/e_jnl.c: Likewise.
        * sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Likewise.

Work around the issue instead of removing -O like we do with
SELECTED_OPTIMIZATION

Upstream-Status: Submitted [https://www.sourceware.org/ml/libc-alpha/2018-09/msg00299.html]

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 ChangeLog                           |  7 +++++++
 sysdeps/ieee754/dbl-64/e_jn.c       | 21 +++++++++++++++++++++
 sysdeps/ieee754/ldbl-128/e_jnl.c    | 21 +++++++++++++++++++++
 sysdeps/ieee754/ldbl-128ibm/e_jnl.c | 21 +++++++++++++++++++++
 sysdeps/ieee754/ldbl-96/e_jnl.c     | 21 +++++++++++++++++++++
 5 files changed, 91 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 11a9b8d98e..922e916f2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-29  Martin Jansa  <Martin.Jansa@gmail.com>
+	Partial fix for [BZ #23716]
+	* sysdeps/ieee754/dbl-96/e_jnl.c: Fix build with -O
+	* sysdeps/ieee754/ldbl-96/e_jnl.c: Likewise.
+	* sysdeps/ieee754/ldbl-128/e_jnl.c: Likewise.
+	* sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Likewise.
+
 2018-09-28  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
 	[BZ #23579]
diff --git a/sysdeps/ieee754/dbl-64/e_jn.c b/sysdeps/ieee754/dbl-64/e_jn.c
index 9181b22bb8..9ff52c737f 100644
--- a/sysdeps/ieee754/dbl-64/e_jn.c
+++ b/sysdeps/ieee754/dbl-64/e_jn.c
@@ -42,6 +42,7 @@
 #include <math-narrow-eval.h>
 #include <math_private.h>
 #include <math-underflow.h>
+#include <libc-diag.h>
 
 static const double
   invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
@@ -109,7 +110,17 @@ __ieee754_jn (int n, double x)
 	      case 2: temp = -c - s; break;
 	      case 3: temp = c - s; break;
 	      }
+	    /* With GCC 8 (and older) when compiling with -O the compiler
+	       warns that the variable 'temp', may be used uninitialized.
+	       The switch above covers all possible values of n & 3
+	       but GCC without VRP enabled isn't able to figure out the
+	       range of possible values is [0,3] as explained in:
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	       so it's false possitive with -O1 and lower. */
+	    DIAG_PUSH_NEEDS_COMMENT;
+	    DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	    b = invsqrtpi * temp / sqrt (x);
+	    DIAG_POP_NEEDS_COMMENT;
 	  }
 	else
 	  {
@@ -316,7 +327,17 @@ __ieee754_yn (int n, double x)
 	  case 2: temp = -s + c; break;
 	  case 3: temp = s + c; break;
 	  }
+	/* With GCC 8 (and older) when compiling with -O the compiler
+	   warns that the variable 'temp', may be used uninitialized.
+	   The switch above covers all possible values of n & 3
+	   but GCC without VRP enabled isn't able to figure out the
+	   range of possible values is [0,3] as explained in:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	   so it's false possitive with -O1 and lower. */
+	DIAG_PUSH_NEEDS_COMMENT;
+	DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	b = invsqrtpi * temp / sqrt (x);
+	DIAG_POP_NEEDS_COMMENT;
       }
     else
       {
diff --git a/sysdeps/ieee754/ldbl-128/e_jnl.c b/sysdeps/ieee754/ldbl-128/e_jnl.c
index 7739eec291..8706a11575 100644
--- a/sysdeps/ieee754/ldbl-128/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-128/e_jnl.c
@@ -61,6 +61,7 @@
 #include <math.h>
 #include <math_private.h>
 #include <math-underflow.h>
+#include <libc-diag.h>
 
 static const _Float128
   invsqrtpi = L(5.6418958354775628694807945156077258584405E-1),
@@ -150,7 +151,17 @@ __ieee754_jnl (int n, _Float128 x)
 		temp = c - s;
 		break;
 	      }
+	    /* With GCC 8 (and older) when compiling with -O the compiler
+	       warns that the variable 'temp', may be used uninitialized.
+	       The switch above covers all possible values of n & 3
+	       but GCC without VRP enabled isn't able to figure out the
+	       range of possible values is [0,3] as explained in:
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	       so it's false possitive with -O1 and lower. */
+	    DIAG_PUSH_NEEDS_COMMENT;
+	    DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	    b = invsqrtpi * temp / sqrtl (x);
+	    DIAG_POP_NEEDS_COMMENT;
 	  }
 	else
 	  {
@@ -386,7 +397,17 @@ __ieee754_ynl (int n, _Float128 x)
 	    temp = s + c;
 	    break;
 	  }
+	/* With GCC 8 (and older) when compiling with -O the compiler
+	   warns that the variable 'temp', may be used uninitialized.
+	   The switch above covers all possible values of n & 3
+	   but GCC without VRP enabled isn't able to figure out the
+	   range of possible values is [0,3] as explained in:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	   so it's false possitive with -O1 and lower. */
+	DIAG_PUSH_NEEDS_COMMENT;
+	DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	b = invsqrtpi * temp / sqrtl (x);
+	DIAG_POP_NEEDS_COMMENT;
       }
     else
       {
diff --git a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
index 71b3addfba..3226d02309 100644
--- a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c
@@ -61,6 +61,7 @@
 #include <math.h>
 #include <math_private.h>
 #include <math-underflow.h>
+#include <libc-diag.h>
 
 static const long double
   invsqrtpi = 5.6418958354775628694807945156077258584405E-1L,
@@ -150,7 +151,17 @@ __ieee754_jnl (int n, long double x)
 		temp = c - s;
 		break;
 	      }
+	    /* With GCC 8 (and older) when compiling with -O the compiler
+	       warns that the variable 'temp', may be used uninitialized.
+	       The switch above covers all possible values of n & 3
+	       but GCC without VRP enabled isn't able to figure out the
+	       range of possible values is [0,3] as explained in:
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	       so it's false possitive with -O1 and lower. */
+	    DIAG_PUSH_NEEDS_COMMENT;
+	    DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	    b = invsqrtpi * temp / sqrtl (x);
+	    DIAG_POP_NEEDS_COMMENT;
 	  }
 	else
 	  {
@@ -386,7 +397,17 @@ __ieee754_ynl (int n, long double x)
 	    temp = s + c;
 	    break;
 	  }
+	/* With GCC 8 (and older) when compiling with -O the compiler
+	   warns that the variable 'temp', may be used uninitialized.
+	   The switch above covers all possible values of n & 3
+	   but GCC without VRP enabled isn't able to figure out the
+	   range of possible values is [0,3] as explained in:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	   so it's false possitive with -O1 and lower. */
+	DIAG_PUSH_NEEDS_COMMENT;
+	DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	b = invsqrtpi * temp / sqrtl (x);
+	DIAG_POP_NEEDS_COMMENT;
       }
     else
       {
diff --git a/sysdeps/ieee754/ldbl-96/e_jnl.c b/sysdeps/ieee754/ldbl-96/e_jnl.c
index 394921f564..da5c2cc93e 100644
--- a/sysdeps/ieee754/ldbl-96/e_jnl.c
+++ b/sysdeps/ieee754/ldbl-96/e_jnl.c
@@ -61,6 +61,7 @@
 #include <math.h>
 #include <math_private.h>
 #include <math-underflow.h>
+#include <libc-diag.h>
 
 static const long double
   invsqrtpi = 5.64189583547756286948079e-1L, two = 2.0e0L, one = 1.0e0L;
@@ -143,7 +144,17 @@ __ieee754_jnl (int n, long double x)
 		temp = c - s;
 		break;
 	      }
+	    /* With GCC 8 (and older) when compiling with -O the compiler
+	       warns that the variable 'temp', may be used uninitialized.
+	       The switch above covers all possible values of n & 3
+	       but GCC without VRP enabled isn't able to figure out the
+	       range of possible values is [0,3] as explained in:
+	       https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	       so it's false possitive with -O1 and lower. */
+	    DIAG_PUSH_NEEDS_COMMENT;
+	    DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	    b = invsqrtpi * temp / sqrtl (x);
+	    DIAG_POP_NEEDS_COMMENT;
 	  }
 	else
 	  {
@@ -372,7 +383,17 @@ __ieee754_ynl (int n, long double x)
 	    temp = s + c;
 	    break;
 	  }
+	/* With GCC 8 (and older) when compiling with -O the compiler
+	   warns that the variable 'temp', may be used uninitialized.
+	   The switch above covers all possible values of n & 3
+	   but GCC without VRP enabled isn't able to figure out the
+	   range of possible values is [0,3] as explained in:
+	   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230
+	   so it's false possitive with -O1 and lower. */
+	DIAG_PUSH_NEEDS_COMMENT;
+	DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	b = invsqrtpi * temp / sqrtl (x);
+	DIAG_POP_NEEDS_COMMENT;
       }
     else
       {