[libc-commits] [libc] [libc] Fix compilation warnings on 32-bit archs (PR #97745)
Mikhail R. Gadelha via libc-commits
libc-commits at lists.llvm.org
Thu Jul 4 08:32:08 PDT 2024
https://github.com/mikhailramalho created https://github.com/llvm/llvm-project/pull/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
>From 52e2bd9e0248b50569d4fd6509ec0a8e1295ce71 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Thu, 4 Jul 2024 12:27:11 -0300
Subject: [PATCH] [libc] Fix compilation warnings on 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
---
libc/src/sched/linux/sched_rr_get_interval.cpp | 2 +-
libc/test/src/__support/time/linux/timeout_test.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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