Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 546b46c309a52ed74dc906114b1e984bb9703d74 Mon Sep 17 00:00:00 2001 |
| 2 | From: Martin Jansa <Martin.Jansa@gmail.com> |
| 3 | Date: Fri, 14 Sep 2018 23:23:03 +0000 |
| 4 | Subject: [PATCH] sysdeps/ieee754: prevent maybe-uninitialized errors with -O |
| 5 | [BZ #19444] |
| 6 | |
| 7 | With -O included in CFLAGS it fails to build with: |
| 8 | |
| 9 | ../sysdeps/ieee754/ldbl-96/e_jnl.c: In function '__ieee754_jnl': |
| 10 | ../sysdeps/ieee754/ldbl-96/e_jnl.c:146:20: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 11 | b = invsqrtpi * temp / sqrtl (x); |
| 12 | ~~~~~~~~~~^~~~~~ |
| 13 | ../sysdeps/ieee754/ldbl-96/e_jnl.c: In function '__ieee754_ynl': |
| 14 | ../sysdeps/ieee754/ldbl-96/e_jnl.c:375:16: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 15 | b = invsqrtpi * temp / sqrtl (x); |
| 16 | ~~~~~~~~~~^~~~~~ |
| 17 | ../sysdeps/ieee754/dbl-64/e_jn.c: In function '__ieee754_jn': |
| 18 | ../sysdeps/ieee754/dbl-64/e_jn.c:113:20: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 19 | b = invsqrtpi * temp / sqrt (x); |
| 20 | ~~~~~~~~~~^~~~~~ |
| 21 | ../sysdeps/ieee754/dbl-64/e_jn.c: In function '__ieee754_yn': |
| 22 | ../sysdeps/ieee754/dbl-64/e_jn.c:320:16: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 23 | b = invsqrtpi * temp / sqrt (x); |
| 24 | ~~~~~~~~~~^~~~~~ |
| 25 | |
| 26 | Build tested with Yocto for ARM, AARCH64, X86, X86_64, PPC, MIPS, MIPS64 |
| 27 | with -O, -O1, -Os. |
| 28 | For soft-fp ARM it needs one more fix for -O1: |
| 29 | https://sourceware.org/ml/libc-alpha/2018-09/msg00300.html |
| 30 | For AARCH64 it needs one more fix in locale for -Os. |
| 31 | |
| 32 | [BZ #23716] |
| 33 | * sysdeps/ieee754/dbl-96/e_jnl.c: Fix build with -O |
| 34 | * sysdeps/ieee754/ldbl-96/e_jnl.c: Likewise. |
| 35 | * sysdeps/ieee754/ldbl-128/e_jnl.c: Likewise. |
| 36 | * sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Likewise. |
| 37 | |
| 38 | Work around the issue instead of removing -O like we do with |
| 39 | SELECTED_OPTIMIZATION |
| 40 | |
| 41 | Upstream-Status: Submitted [https://www.sourceware.org/ml/libc-alpha/2018-09/msg00299.html] |
| 42 | |
| 43 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> |
| 44 | --- |
| 45 | ChangeLog | 7 +++++++ |
| 46 | sysdeps/ieee754/dbl-64/e_jn.c | 21 +++++++++++++++++++++ |
| 47 | sysdeps/ieee754/ldbl-128/e_jnl.c | 21 +++++++++++++++++++++ |
| 48 | sysdeps/ieee754/ldbl-128ibm/e_jnl.c | 21 +++++++++++++++++++++ |
| 49 | sysdeps/ieee754/ldbl-96/e_jnl.c | 21 +++++++++++++++++++++ |
| 50 | 5 files changed, 91 insertions(+) |
| 51 | |
| 52 | diff --git a/ChangeLog b/ChangeLog |
| 53 | index 11a9b8d98e..922e916f2c 100644 |
| 54 | --- a/ChangeLog |
| 55 | +++ b/ChangeLog |
| 56 | @@ -1,3 +1,10 @@ |
| 57 | +2018-09-29 Martin Jansa <Martin.Jansa@gmail.com> |
| 58 | + Partial fix for [BZ #23716] |
| 59 | + * sysdeps/ieee754/dbl-96/e_jnl.c: Fix build with -O |
| 60 | + * sysdeps/ieee754/ldbl-96/e_jnl.c: Likewise. |
| 61 | + * sysdeps/ieee754/ldbl-128/e_jnl.c: Likewise. |
| 62 | + * sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Likewise. |
| 63 | + |
| 64 | 2018-09-28 Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 65 | |
| 66 | [BZ #23579] |
| 67 | diff --git a/sysdeps/ieee754/dbl-64/e_jn.c b/sysdeps/ieee754/dbl-64/e_jn.c |
| 68 | index 9181b22bb8..9ff52c737f 100644 |
| 69 | --- a/sysdeps/ieee754/dbl-64/e_jn.c |
| 70 | +++ b/sysdeps/ieee754/dbl-64/e_jn.c |
| 71 | @@ -42,6 +42,7 @@ |
| 72 | #include <math-narrow-eval.h> |
| 73 | #include <math_private.h> |
| 74 | #include <math-underflow.h> |
| 75 | +#include <libc-diag.h> |
| 76 | |
| 77 | static const double |
| 78 | invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */ |
| 79 | @@ -109,7 +110,17 @@ __ieee754_jn (int n, double x) |
| 80 | case 2: temp = -c - s; break; |
| 81 | case 3: temp = c - s; break; |
| 82 | } |
| 83 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 84 | + warns that the variable 'temp', may be used uninitialized. |
| 85 | + The switch above covers all possible values of n & 3 |
| 86 | + but GCC without VRP enabled isn't able to figure out the |
| 87 | + range of possible values is [0,3] as explained in: |
| 88 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 89 | + so it's false possitive with -O1 and lower. */ |
| 90 | + DIAG_PUSH_NEEDS_COMMENT; |
| 91 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 92 | b = invsqrtpi * temp / sqrt (x); |
| 93 | + DIAG_POP_NEEDS_COMMENT; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | @@ -316,7 +327,17 @@ __ieee754_yn (int n, double x) |
| 98 | case 2: temp = -s + c; break; |
| 99 | case 3: temp = s + c; break; |
| 100 | } |
| 101 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 102 | + warns that the variable 'temp', may be used uninitialized. |
| 103 | + The switch above covers all possible values of n & 3 |
| 104 | + but GCC without VRP enabled isn't able to figure out the |
| 105 | + range of possible values is [0,3] as explained in: |
| 106 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 107 | + so it's false possitive with -O1 and lower. */ |
| 108 | + DIAG_PUSH_NEEDS_COMMENT; |
| 109 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 110 | b = invsqrtpi * temp / sqrt (x); |
| 111 | + DIAG_POP_NEEDS_COMMENT; |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | diff --git a/sysdeps/ieee754/ldbl-128/e_jnl.c b/sysdeps/ieee754/ldbl-128/e_jnl.c |
| 116 | index 7739eec291..8706a11575 100644 |
| 117 | --- a/sysdeps/ieee754/ldbl-128/e_jnl.c |
| 118 | +++ b/sysdeps/ieee754/ldbl-128/e_jnl.c |
| 119 | @@ -61,6 +61,7 @@ |
| 120 | #include <math.h> |
| 121 | #include <math_private.h> |
| 122 | #include <math-underflow.h> |
| 123 | +#include <libc-diag.h> |
| 124 | |
| 125 | static const _Float128 |
| 126 | invsqrtpi = L(5.6418958354775628694807945156077258584405E-1), |
| 127 | @@ -150,7 +151,17 @@ __ieee754_jnl (int n, _Float128 x) |
| 128 | temp = c - s; |
| 129 | break; |
| 130 | } |
| 131 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 132 | + warns that the variable 'temp', may be used uninitialized. |
| 133 | + The switch above covers all possible values of n & 3 |
| 134 | + but GCC without VRP enabled isn't able to figure out the |
| 135 | + range of possible values is [0,3] as explained in: |
| 136 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 137 | + so it's false possitive with -O1 and lower. */ |
| 138 | + DIAG_PUSH_NEEDS_COMMENT; |
| 139 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 140 | b = invsqrtpi * temp / sqrtl (x); |
| 141 | + DIAG_POP_NEEDS_COMMENT; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | @@ -386,7 +397,17 @@ __ieee754_ynl (int n, _Float128 x) |
| 146 | temp = s + c; |
| 147 | break; |
| 148 | } |
| 149 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 150 | + warns that the variable 'temp', may be used uninitialized. |
| 151 | + The switch above covers all possible values of n & 3 |
| 152 | + but GCC without VRP enabled isn't able to figure out the |
| 153 | + range of possible values is [0,3] as explained in: |
| 154 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 155 | + so it's false possitive with -O1 and lower. */ |
| 156 | + DIAG_PUSH_NEEDS_COMMENT; |
| 157 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 158 | b = invsqrtpi * temp / sqrtl (x); |
| 159 | + DIAG_POP_NEEDS_COMMENT; |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | diff --git a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c |
| 164 | index 71b3addfba..3226d02309 100644 |
| 165 | --- a/sysdeps/ieee754/ldbl-128ibm/e_jnl.c |
| 166 | +++ b/sysdeps/ieee754/ldbl-128ibm/e_jnl.c |
| 167 | @@ -61,6 +61,7 @@ |
| 168 | #include <math.h> |
| 169 | #include <math_private.h> |
| 170 | #include <math-underflow.h> |
| 171 | +#include <libc-diag.h> |
| 172 | |
| 173 | static const long double |
| 174 | invsqrtpi = 5.6418958354775628694807945156077258584405E-1L, |
| 175 | @@ -150,7 +151,17 @@ __ieee754_jnl (int n, long double x) |
| 176 | temp = c - s; |
| 177 | break; |
| 178 | } |
| 179 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 180 | + warns that the variable 'temp', may be used uninitialized. |
| 181 | + The switch above covers all possible values of n & 3 |
| 182 | + but GCC without VRP enabled isn't able to figure out the |
| 183 | + range of possible values is [0,3] as explained in: |
| 184 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 185 | + so it's false possitive with -O1 and lower. */ |
| 186 | + DIAG_PUSH_NEEDS_COMMENT; |
| 187 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 188 | b = invsqrtpi * temp / sqrtl (x); |
| 189 | + DIAG_POP_NEEDS_COMMENT; |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | @@ -386,7 +397,17 @@ __ieee754_ynl (int n, long double x) |
| 194 | temp = s + c; |
| 195 | break; |
| 196 | } |
| 197 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 198 | + warns that the variable 'temp', may be used uninitialized. |
| 199 | + The switch above covers all possible values of n & 3 |
| 200 | + but GCC without VRP enabled isn't able to figure out the |
| 201 | + range of possible values is [0,3] as explained in: |
| 202 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 203 | + so it's false possitive with -O1 and lower. */ |
| 204 | + DIAG_PUSH_NEEDS_COMMENT; |
| 205 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 206 | b = invsqrtpi * temp / sqrtl (x); |
| 207 | + DIAG_POP_NEEDS_COMMENT; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | diff --git a/sysdeps/ieee754/ldbl-96/e_jnl.c b/sysdeps/ieee754/ldbl-96/e_jnl.c |
| 212 | index 394921f564..da5c2cc93e 100644 |
| 213 | --- a/sysdeps/ieee754/ldbl-96/e_jnl.c |
| 214 | +++ b/sysdeps/ieee754/ldbl-96/e_jnl.c |
| 215 | @@ -61,6 +61,7 @@ |
| 216 | #include <math.h> |
| 217 | #include <math_private.h> |
| 218 | #include <math-underflow.h> |
| 219 | +#include <libc-diag.h> |
| 220 | |
| 221 | static const long double |
| 222 | invsqrtpi = 5.64189583547756286948079e-1L, two = 2.0e0L, one = 1.0e0L; |
| 223 | @@ -143,7 +144,17 @@ __ieee754_jnl (int n, long double x) |
| 224 | temp = c - s; |
| 225 | break; |
| 226 | } |
| 227 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 228 | + warns that the variable 'temp', may be used uninitialized. |
| 229 | + The switch above covers all possible values of n & 3 |
| 230 | + but GCC without VRP enabled isn't able to figure out the |
| 231 | + range of possible values is [0,3] as explained in: |
| 232 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 233 | + so it's false possitive with -O1 and lower. */ |
| 234 | + DIAG_PUSH_NEEDS_COMMENT; |
| 235 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 236 | b = invsqrtpi * temp / sqrtl (x); |
| 237 | + DIAG_POP_NEEDS_COMMENT; |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | @@ -372,7 +383,17 @@ __ieee754_ynl (int n, long double x) |
| 242 | temp = s + c; |
| 243 | break; |
| 244 | } |
| 245 | + /* With GCC 8 (and older) when compiling with -O the compiler |
| 246 | + warns that the variable 'temp', may be used uninitialized. |
| 247 | + The switch above covers all possible values of n & 3 |
| 248 | + but GCC without VRP enabled isn't able to figure out the |
| 249 | + range of possible values is [0,3] as explained in: |
| 250 | + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69230 |
| 251 | + so it's false possitive with -O1 and lower. */ |
| 252 | + DIAG_PUSH_NEEDS_COMMENT; |
| 253 | + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 254 | b = invsqrtpi * temp / sqrtl (x); |
| 255 | + DIAG_POP_NEEDS_COMMENT; |
| 256 | } |
| 257 | else |
| 258 | { |