[libcxx-commits] [PATCH] D112837: [SystemZ][z/OS] Fix warnings from unsigned int to long in 32-bit mode

Zibi Sarbino via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 29 11:39:35 PDT 2021


zibi created this revision.
zibi requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This patch fixes the warnings which shows up when libcxx library started to be compiled in 32-bit mode on z/OS.
More specifically, the assignment from unsigned int to time_t aka long was flags as follows:

libcxx/include/c++/v1/__support/ibm/nanosleep.h:31:11: warning: implicit conversion changes signedness: 'unsigned int' to 'time_t' (aka 'long') [-Wsign-conversion]

  __sec = sleep(static_cast<unsigned int>(__sec));
        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

libcxx/include/c++/v1/__support/ibm/nanosleep.h:36:36: warning: implicit conversion changes signedness: 'unsigned int' to 'long' [-Wsign-conversion]

  __rem->tv_nsec = __micro_sec * 1000;
                 ~ ~~~~~~~~~~~~^~~~~~

libcxx/include/c++/v1/__support/ibm/nanosleep.h:47:36: warning: implicit conversion changes signedness: 'unsigned int' to 'long' [-Wsign-conversion]

  __rem->tv_nsec = __micro_sec * 1000;
                 ~ ~~~~~~~~~~~~^~~~~~

3 warnings generated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112837

Files:
  libcxx/include/__support/ibm/nanosleep.h


Index: libcxx/include/__support/ibm/nanosleep.h
===================================================================
--- libcxx/include/__support/ibm/nanosleep.h
+++ libcxx/include/__support/ibm/nanosleep.h
@@ -21,14 +21,13 @@
     errno = EINVAL;
     return -1;
   }
-  useconds_t __micro_sec =
-      static_cast<useconds_t>((__req->tv_nsec + 999) / 1000);
+  long __micro_sec = (__req->tv_nsec + 999) / 1000;
   time_t __sec = __req->tv_sec;
   if (__micro_sec > 999999) {
     ++__sec;
     __micro_sec -= 1000000;
   }
-  __sec = sleep(static_cast<unsigned int>(__sec));
+  __sec = static_cast<time_t>(sleep(static_cast<unsigned int>(__sec)));
   if (__sec) {
     if (__rem) {
       // Updating the remaining time to sleep in case of unsuccessful call to sleep().
@@ -39,7 +38,7 @@
     return -1;
   }
   if (__micro_sec) {
-    int __rt = usleep(__micro_sec);
+    int __rt = usleep(static_cast<unsigned int>(__micro_sec));
     if (__rt != 0 && __rem) {
       // The usleep() does not provide the amount of remaining time upon its failure,
       // so the time slept will be ignored.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112837.383441.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211029/e98b6373/attachment-0001.bin>


More information about the libcxx-commits mailing list