[libc-commits] [libc] 8bb4294 - [libc] Fix compilation warnings on 32-bit archs (#97745)

via libc-commits libc-commits at lists.llvm.org
Thu Jul 4 09:34:18 PDT 2024


Author: Mikhail R. Gadelha
Date: 2024-07-04T13:34:15-03:00
New Revision: 8bb4294be71e10eca02e23aab4f17af905687c4a

URL: https://github.com/llvm/llvm-project/commit/8bb4294be71e10eca02e23aab4f17af905687c4a
DIFF: https://github.com/llvm/llvm-project/commit/8bb4294be71e10eca02e23aab4f17af905687c4a.diff

LOG: [libc] Fix compilation warnings on 32-bit archs (#97745)

timespec's tv_nsec is a long int, which has different sizes in 32-bit and 64-bit platforms, so this patch adds one and fixes another static_cast throw warnings in 32-bit archs

Added: 
    

Modified: 
    libc/src/sched/linux/sched_rr_get_interval.cpp
    libc/test/src/__support/time/linux/timeout_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/sched/linux/sched_rr_get_interval.cpp b/libc/src/sched/linux/sched_rr_get_interval.cpp
index 9d7d0e9d1ef6a..5dcac203bb418 100644
--- a/libc/src/sched/linux/sched_rr_get_interval.cpp
+++ b/libc/src/sched/linux/sched_rr_get_interval.cpp
@@ -36,7 +36,7 @@ LLVM_LIBC_FUNCTION(int, sched_rr_get_interval,
                                             tid, &ts32);
     if (ret == 0) {
       tp->tv_sec = ts32.tv_sec;
-      tp->tv_nsec = ts32.tv_nsec;
+      tp->tv_nsec = static_cast<long int>(ts32.tv_nsec);
     }
   } else
     // When tp is a nullptr, we still do the syscall to set ret and errno

diff  --git a/libc/test/src/__support/time/linux/timeout_test.cpp b/libc/test/src/__support/time/linux/timeout_test.cpp
index 886d4389709e8..37b3763332e2d 100644
--- a/libc/test/src/__support/time/linux/timeout_test.cpp
+++ b/libc/test/src/__support/time/linux/timeout_test.cpp
@@ -45,7 +45,7 @@ TEST(LlvmLibcSupportLinuxTimeoutTest, NoChangeIfClockIsMonotonic) {
   ensure_monotonicity(*result);
   ASSERT_FALSE(result->is_realtime());
   ASSERT_EQ(result->get_timespec().tv_sec, static_cast<time_t>(10000));
-  ASSERT_EQ(result->get_timespec().tv_nsec, static_cast<time_t>(0));
+  ASSERT_EQ(result->get_timespec().tv_nsec, static_cast<long int>(0));
 }
 TEST(LlvmLibcSupportLinuxTimeoutTest, ValidAfterConversion) {
   timespec ts;


        


More information about the libc-commits mailing list