Skip to content

[libc] Fix compilation warnings on 32-bit archs #97745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

mikhailramalho
Copy link
Member

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

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
@llvmbot
Copy link
Member

llvmbot commented Jul 4, 2024

@llvm/pr-subscribers-libc

Author: Mikhail R. Gadelha (mikhailramalho)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/97745.diff

2 Files Affected:

  • (modified) libc/src/sched/linux/sched_rr_get_interval.cpp (+1-1)
  • (modified) libc/test/src/__support/time/linux/timeout_test.cpp (+1-1)
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;

@mikhailramalho mikhailramalho merged commit 8bb4294 into llvm:main Jul 4, 2024
6 of 7 checks passed
@mikhailramalho mikhailramalho deleted the fix-timet branch July 4, 2024 16:34
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants