[libc-commits] [libc] [libc][fcntl] fix -Wshorten-64-to-32 for 32b ARM (PR #95945)

via libc-commits libc-commits at lists.llvm.org
Tue Jun 18 08:39:40 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (paternity leave) (nickdesaulniers)

<details>
<summary>Changes</summary>

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.

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


1 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/fcntl.cpp (+2-2) 


``````````diff
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;
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/95945


More information about the libc-commits mailing list