[libc-commits] [libc] [libc][NFC] Adjust use of off_t internally (PR #68269)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Thu Oct 5 01:49:10 PDT 2023
================
@@ -19,15 +19,18 @@ namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(ssize_t, pread,
(int fd, void *buf, size_t count, off_t offset)) {
-#ifdef LIBC_TARGET_ARCH_IS_RISCV32
- static_assert(sizeof(off_t) == 8);
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(
- SYS_pread64, fd, buf, count, (long)offset,
- (long)(((uint64_t)(offset)) >> 32));
-#else
- ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_pread64, fd, buf,
- count, offset);
-#endif
+ ssize_t ret;
+ if constexpr (sizeof(off_t) == 8 && sizeof(size_t) == 4) {
+ // This is a 32-bit system with a 64-bit offset.
+ long offset_low = static_cast<long>(offset);
+ long offset_high = static_cast<long>(offset >> 32);
----------------
gchatelet wrote:
Bystander comment, is this supposed to split offset 8 bytes into two 4 bytes ?
If so I find this code suspicious for several reasons:
- why test `sizeof(size_t) == 4` if we're actually using the `long` type in the syscall?
- to get the low bits I would expect to see a mask, I see a cast and so the semantic seems unclear,
- what happens to the sign bit in case `offset` is negative?
I'm not saying the code is wrong, but it's not obviously correct either.
https://github.com/llvm/llvm-project/pull/68269
More information about the libc-commits
mailing list