Message ID | 4c7fda1e-d0fe-d373-9694-d1ce09084ec2@linux.ibm.com |
---|---|
State | New |
Headers | show |
Series | Get rid of Werror=maybe-uninitialized in clock_nanosleep.c. | expand |
On 12/3/19 9:50 AM, Stefan Liebler wrote: > 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 ping
On 12/9/19 1:59 PM, Stefan Liebler wrote: > On 12/3/19 9:50 AM, Stefan Liebler wrote: >> 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 > > ping > ping
On 12/13/19 1:43 PM, Stefan Liebler wrote: > On 12/9/19 1:59 PM, Stefan Liebler wrote: >> On 12/3/19 9:50 AM, Stefan Liebler wrote: >>> 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 >> >> ping >> > ping > This warning does not occur anymore starting with the commit "Linux: Fix clock_nanosleep time64 check" https://sourceware.org/git/?p=glibc.git;a=commit;h=b03688bfbb072f42970747bc2e6362c24b4b7ee8
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