This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2] Fix maybe-uninitialized error on powerpc
- From: Matheus Castanho <msc at linux dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Cc: joseph at codesourcery dot com, siddhesh at sourceware dot org
- Date: Fri, 17 Jan 2020 11:44:54 -0300
- Subject: [PATCH v2] Fix maybe-uninitialized error on powerpc
Changes for v2:
- Use __builtin_unreachable so compiler ignores false-positive
- Add comment with proper explanation
----8<----
The build has been failing on powerpc64le-linux-gnu with GCC 10
due to a maybe-uninitialized error:
../sysdeps/ieee754/dbl-64/mpa.c:875:6: error: ‘w.e’ may be used
uninitialized in this function [-Werror=maybe-uninitialized]
875 | EY -= EX;
| ^~
The warning is thrown because when __inv is called by __dvd *y is not
initialized and if t == 0 before calling __dbl_mp, EY will stay
uninitialized, as the function does not touch it in this case.
However, since t will be set to 1/t before calling __dbl_mp, t == 0 will
never happen, so we can instruct the compiler to ignore this case, which
suppresses the warning.
Tested on powerpc64le.
---
sysdeps/ieee754/dbl-64/mpa.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/sysdeps/ieee754/dbl-64/mpa.c b/sysdeps/ieee754/dbl-64/mpa.c
index 3bb8bff90d..0bcba09e24 100644
--- a/sysdeps/ieee754/dbl-64/mpa.c
+++ b/sysdeps/ieee754/dbl-64/mpa.c
@@ -871,6 +871,13 @@ __inv (const mp_no *x, mp_no *y, int p)
z.e = 0;
__mp_dbl (&z, &t, p);
t = 1 / t;
+
+ /* t == 0 will never happen at this point, since 1/t can only be 0 if t is
+ infinity, but before the division t == mantissa of x (exponent is 0). We
+ can instruct the compiler to ignore this case. */
+ if (t == 0)
+ __builtin_unreachable();
+
__dbl_mp (t, y, p);
EY -= EX;
--
2.21.1