[libc-commits] [libc] [libc] Added static casts to fix implicit conversion warnings in 32-bit systems (PR #99769)
via libc-commits
libc-commits at lists.llvm.org
Sat Jul 20 09:16:53 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mikhail R. Gadelha (mikhailramalho)
<details>
<summary>Changes</summary>
This patch fixes:
* randomness.h and getauxval.cpp were passing ssize_t as size_t
* kernel_statx.h was assigning an uint64_t to uintptr_t
* fopencookie.cpp was trying to create a FileIOResult using ssize_t but the constructor expected a size_t
* thread.h was trying to call free_stack (which takes a size_t) with an unsigned long long. free_stack does the calculations using uintptr_t, so I changed the passing values to size_t
---
Full diff: https://github.com/llvm/llvm-project/pull/99769.diff
5 Files Affected:
- (modified) libc/src/__support/HashTable/randomness.h (+1-1)
- (modified) libc/src/__support/threads/thread.h (+5-5)
- (modified) libc/src/stdio/fopencookie.cpp (+4-4)
- (modified) libc/src/sys/auxv/linux/getauxval.cpp (+1-1)
- (modified) libc/src/sys/stat/linux/kernel_statx.h (+2-2)
``````````diff
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 06d3e84a710e7..244dd41be3eec 100644
--- a/libc/src/__support/HashTable/randomness.h
+++ b/libc/src/__support/HashTable/randomness.h
@@ -36,7 +36,7 @@ LIBC_INLINE uint64_t next_random_seed() {
entropy[1] = reinterpret_cast<uint64_t>(&state);
#if defined(LIBC_HASHTABLE_USE_GETRANDOM)
int errno_backup = libc_errno;
- ssize_t count = sizeof(entropy);
+ size_t count = sizeof(entropy);
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
while (count > 0) {
ssize_t len = getrandom(buffer, count, 0);
diff --git a/libc/src/__support/threads/thread.h b/libc/src/__support/threads/thread.h
index ce23a880e048a..909d2088df2fa 100644
--- a/libc/src/__support/threads/thread.h
+++ b/libc/src/__support/threads/thread.h
@@ -97,11 +97,11 @@ struct alignas(STACK_ALIGNMENT) ThreadAttributes {
// exits. It will clean up the thread resources once the thread
// exits.
cpp::Atomic<uint32_t> detach_state;
- void *stack; // Pointer to the thread stack
- unsigned long long stacksize; // Size of the stack
- unsigned long long guardsize; // Guard size on stack
- uintptr_t tls; // Address to the thread TLS memory
- uintptr_t tls_size; // The size of area pointed to by |tls|.
+ void *stack; // Pointer to the thread stack
+ size_t stacksize; // Size of the stack
+ size_t guardsize; // Guard size on stack
+ uintptr_t tls; // Address to the thread TLS memory
+ uintptr_t tls_size; // The size of area pointed to by |tls|.
unsigned char owned_stack; // Indicates if the thread owns this stack memory
int tid;
ThreadStyle style;
diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp
index 07be9a5635a92..9f5694e8e0581 100644
--- a/libc/src/stdio/fopencookie.cpp
+++ b/libc/src/stdio/fopencookie.cpp
@@ -43,16 +43,16 @@ FileIOResult CookieFile::cookie_write(File *f, const void *data, size_t size) {
auto cookie_file = reinterpret_cast<CookieFile *>(f);
if (cookie_file->ops.write == nullptr)
return 0;
- return cookie_file->ops.write(cookie_file->cookie,
- reinterpret_cast<const char *>(data), size);
+ return static_cast<size_t>(cookie_file->ops.write(
+ cookie_file->cookie, reinterpret_cast<const char *>(data), size));
}
FileIOResult CookieFile::cookie_read(File *f, void *data, size_t size) {
auto cookie_file = reinterpret_cast<CookieFile *>(f);
if (cookie_file->ops.read == nullptr)
return 0;
- return cookie_file->ops.read(cookie_file->cookie,
- reinterpret_cast<char *>(data), size);
+ return static_cast<size_t>(cookie_file->ops.read(
+ cookie_file->cookie, reinterpret_cast<char *>(data), size));
}
ErrorOr<off_t> CookieFile::cookie_seek(File *f, off_t offset, int whence) {
diff --git a/libc/src/sys/auxv/linux/getauxval.cpp b/libc/src/sys/auxv/linux/getauxval.cpp
index 2ca894d091532..bfa6b23b5ef91 100644
--- a/libc/src/sys/auxv/linux/getauxval.cpp
+++ b/libc/src/sys/auxv/linux/getauxval.cpp
@@ -155,7 +155,7 @@ static void initialize_auxv_once(void) {
static AuxEntry read_entry(int fd) {
AuxEntry buf;
- ssize_t size = sizeof(AuxEntry);
+ size_t size = sizeof(AuxEntry);
char *ptr = reinterpret_cast<char *>(&buf);
while (size > 0) {
ssize_t ret = read(fd, ptr, size);
diff --git a/libc/src/sys/stat/linux/kernel_statx.h b/libc/src/sys/stat/linux/kernel_statx.h
index f26f0b826ac1e..634a855ed163d 100644
--- a/libc/src/sys/stat/linux/kernel_statx.h
+++ b/libc/src/sys/stat/linux/kernel_statx.h
@@ -80,7 +80,7 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
return -ret;
statbuf->st_dev = MKDEV(xbuf.stx_dev_major, xbuf.stx_dev_minor);
- statbuf->st_ino = xbuf.stx_ino;
+ statbuf->st_ino = static_cast<decltype(statbuf->st_ino)>(xbuf.stx_ino);
statbuf->st_mode = xbuf.stx_mode;
statbuf->st_nlink = xbuf.stx_nlink;
statbuf->st_uid = xbuf.stx_uid;
@@ -94,7 +94,7 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
statbuf->st_ctim.tv_sec = xbuf.stx_ctime.tv_sec;
statbuf->st_ctim.tv_nsec = xbuf.stx_ctime.tv_nsec;
statbuf->st_blksize = xbuf.stx_blksize;
- statbuf->st_blocks = xbuf.stx_blocks;
+ statbuf->st_blocks = static_cast<decltype(statbuf->st_blocks)>(xbuf.stx_blocks);
return 0;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/99769
More information about the libc-commits
mailing list