[libc-commits] [libc] [libc] Fix compilation warnings on 32-bit archs (PR #97745)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 4 08:32:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mikhail R. Gadelha (mikhailramalho)
<details>
<summary>Changes</summary>
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
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/97745
More information about the libc-commits
mailing list