This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
- From: Stefan Liebler <stli at linux dot ibm dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 3 Dec 2019 09:50:24 +0100
- Subject: [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
Hi,
If build with -O3 on s390 (31bit) on kernels < 5.1, there are the
following werrors:
../sysdeps/unix/sysv/linux/clock_nanosleep.c:91:12: error: ‘*((void
*)&trem64+12)’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
*rem = valid_timespec64_to_timespec (trem64);
../include/time.h:264:15: error: ‘trem64’ may be used uninitialized in
this function [-Werror=maybe-uninitialized]
ts.tv_sec = (time_t) ts64.tv_sec;
This patch moves the calculation of r before the if condition. Then GCC
recognizes that the condition here and in __clock_nanosleep equals and that
trem64 in __clock_nanosleep is initialized.
Bye
Stefan
commit 1d23f5b16a99281faa523e21e137472059bc3f5f
Author: Stefan Liebler <stli@linux.ibm.com>
Date: Mon Dec 2 11:47:00 2019 +0100
Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
If build with -O3 on s390 (31bit) on kernels < 5.1, there are the following werrors:
../sysdeps/unix/sysv/linux/clock_nanosleep.c:91:12: error: ‘*((void *)&trem64+12)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
*rem = valid_timespec64_to_timespec (trem64);
../include/time.h:264:15: error: ‘trem64’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
ts.tv_sec = (time_t) ts64.tv_sec;
This patch moves the calculation of r before the if condition. Then GCC
recognizes that the condition here and in __clock_nanosleep equals and that
trem64 in __clock_nanosleep is initialized.
diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c
index fc47c58ee7..c9e1072354 100644
--- a/sysdeps/unix/sysv/linux/clock_nanosleep.c
+++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -47,6 +47,9 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec
# endif
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, clock_id,
flags, req, rem);
+
+ r = (INTERNAL_SYSCALL_ERROR_P (r, err)
+ ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
#else
# ifdef __NR_clock_nanosleep_time64
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, clock_id,
@@ -68,12 +71,16 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags, const struct __timespec
r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep, err, clock_id, flags,
&ts32, &tr32);
- if (r == -EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0)
+ /* Calculate r before the following if condition. Then GCC recognizes
+ that the condition here and in __clock_nanosleep equals and that
+ trem64 in __clock_nanosleep is initialized. */
+ r = (INTERNAL_SYSCALL_ERROR_P (r, err)
+ ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
+ if (r == EINTR && rem != NULL && (flags & TIMER_ABSTIME) == 0)
*rem = valid_timespec_to_timespec64 (tr32);
#endif /* __ASSUME_TIME64_SYSCALLS */
- return (INTERNAL_SYSCALL_ERROR_P (r, err)
- ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
+ return r;
}
#if __TIMESIZE != 64