[libc-commits] [libc] [libc][fcntl] fix -Wshorten-64-to-32 for 32b ARM (PR #95945)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jun 18 08:39:10 PDT 2024
https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/95945
Fixes:
llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:63:26: error:
implicit conversion loses integer precision: '__off64_t' (aka 'long long')
to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32]
flk->l_start = flk64.l_start;
~ ~~~~~~^~~~~~~
llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:64:24: error:
implicit conversion loses integer precision: '__off64_t' (aka 'long long')
to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32]
flk->l_len = flk64.l_len;
~ ~~~~~~^~~~~
We already have an overflow check, just need the cast to be explicit. This
warning was observed on the 32b ARM build in overlay mode.
>From bcb73f908a414bb706eafd2ba8347d944a82efde Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 18 Jun 2024 08:36:49 -0700
Subject: [PATCH] [libc][fcntl] fix -Wshorten-64-to-32 for 32b ARM
Fixes:
llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:63:26: error:
implicit conversion loses integer precision: '__off64_t' (aka 'long long')
to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32]
flk->l_start = flk64.l_start;
~ ~~~~~~^~~~~~~
llvm-project/libc/src/__support/OSUtil/linux/fcntl.cpp:64:24: error:
implicit conversion loses integer precision: '__off64_t' (aka 'long long')
to '__off_t' (aka 'long') [-Werror,-Wshorten-64-to-32]
flk->l_len = flk64.l_len;
~ ~~~~~~^~~~~
We already have an overflow check, just need the cast to be explicit. This
warning was observed on the 32b ARM build in overlay mode.
---
libc/src/__support/OSUtil/linux/fcntl.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/fcntl.cpp b/libc/src/__support/OSUtil/linux/fcntl.cpp
index 7dc416a7916df..b087f898c395d 100644
--- a/libc/src/__support/OSUtil/linux/fcntl.cpp
+++ b/libc/src/__support/OSUtil/linux/fcntl.cpp
@@ -60,8 +60,8 @@ int fcntl(int fd, int cmd, void *arg) {
// Now copy back into flk, in case flk64 got modified
flk->l_type = flk64.l_type;
flk->l_whence = flk64.l_whence;
- flk->l_start = flk64.l_start;
- flk->l_len = flk64.l_len;
+ flk->l_start = static_cast<decltype(flk->l_start)>(flk64.l_start);
+ flk->l_len = static_cast<decltype(flk->l_len)>(flk64.l_len);
flk->l_pid = flk64.l_pid;
return retVal;
}
More information about the libc-commits
mailing list