[libc-commits] [libc] [libc] fix -Wshorten-64-to-32 for 32b arm mmap (PR #77350)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Mon Jan 8 10:28:48 PST 2024
https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/77350
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).
>From a10693c80a733511a722209ffe4488cdcef9ae50 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 8 Jan 2024 10:26:00 -0800
Subject: [PATCH] [libc] fix -Wshorten-64-to-32 for 32b arm mmap
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).
---
libc/include/llvm-libc-types/off_t.h | 4 ++++
1 file changed, 4 insertions(+)
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__
More information about the libc-commits
mailing list