From patchwork Tue Dec 3 08:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 36456 Received: (qmail 3445 invoked by alias); 3 Dec 2019 08:50:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3437 invoked by uid 89); 3 Dec 2019 08:50:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx0a-001b2d01.pphosted.com To: GNU C Library From: Stefan Liebler Subject: [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c. Date: Tue, 3 Dec 2019 09:50:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 x-cbid: 19120308-0020-0000-0000-00000392F16E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19120308-0021-0000-0000-000021EA10B4 Message-Id: <4c7fda1e-d0fe-d373-9694-d1ce09084ec2@linux.ibm.com> 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 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