public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
@ 2019-12-03  8:50 Stefan Liebler
  2019-12-09 13:00 ` Stefan Liebler
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2019-12-03  8:50 UTC (permalink / raw)
  To: GNU C Library

[-- Attachment #1: Type: text/plain, Size: 672 bytes --]

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

[-- Attachment #2: 20191202_werror_clock_nanosleep.patch --]
[-- Type: text/x-patch, Size: 2431 bytes --]

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
  2019-12-03  8:50 [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c Stefan Liebler
@ 2019-12-09 13:00 ` Stefan Liebler
  2019-12-13 12:43   ` Stefan Liebler
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2019-12-09 13:00 UTC (permalink / raw)
  To: libc-alpha

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
  2019-12-09 13:00 ` Stefan Liebler
@ 2019-12-13 12:43   ` Stefan Liebler
  2020-01-08  7:47     ` Stefan Liebler
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2019-12-13 12:43 UTC (permalink / raw)
  To: libc-alpha

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c.
  2019-12-13 12:43   ` Stefan Liebler
@ 2020-01-08  7:47     ` Stefan Liebler
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Liebler @ 2020-01-08  7:47 UTC (permalink / raw)
  To: libc-alpha

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-08  7:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03  8:50 [PATCH] Get rid of Werror=maybe-uninitialized in clock_nanosleep.c Stefan Liebler
2019-12-09 13:00 ` Stefan Liebler
2019-12-13 12:43   ` Stefan Liebler
2020-01-08  7:47     ` Stefan Liebler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).