[libc-commits] [libc] [libc] fix -Wshorten-64-to-32 for 32b arm mmap (PR #77350)

via libc-commits libc-commits at lists.llvm.org
Mon Jan 8 10:29:18 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

<details>
<summary>Changes</summary>

Fixes the following diagnostic:

    llvm-project/libc/src/sys/mman/linux/mmap.cpp:44:59: error: implicit
    conversion loses integer precision: 'off_t' (aka 'long long') to 'long'
    [-Werror,-Wshorten-64-to-32]
     size, prot, flags, fd, offset);
                            ^~~~~~

It looks like off_t is a curious types on different platforms.  FWICT, it's 32b
on arm (at least for arm-linux-gnueabi) but 64b elsewhere (including 32b
riscv-linux-gnu).


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


1 Files Affected:

- (modified) libc/include/llvm-libc-types/off_t.h (+4) 


``````````diff
diff --git a/libc/include/llvm-libc-types/off_t.h b/libc/include/llvm-libc-types/off_t.h
index 111b29aa68d875..f1c38d6bb5ad43 100644
--- a/libc/include/llvm-libc-types/off_t.h
+++ b/libc/include/llvm-libc-types/off_t.h
@@ -9,6 +9,10 @@
 #ifndef __LLVM_LIBC_TYPES_OFF_T_H__
 #define __LLVM_LIBC_TYPES_OFF_T_H__
 
+#if defined(__LP64__) || defined (__riscv)
 typedef __INT64_TYPE__ off_t;
+#else
+typedef __INT32_TYPE__ off_t;
+#endif // __LP64__ || __riscv
 
 #endif // __LLVM_LIBC_TYPES_OFF_T_H__

``````````

</details>


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


More information about the libc-commits mailing list