aboutsummaryrefslogtreecommitdiff
path: root/libc/src
diff options
context:
space:
mode:
authorMikhail R. Gadelha <mikhail@igalia.com>2024-07-20 20:12:31 +0200
committerGitHub <noreply@github.com>2024-07-20 15:12:31 -0300
commit91bf0a073951aa1ca4c357967ed5aff891941785 (patch)
tree3718f9966daec1264c91902ea7b2edb69966cf72 /libc/src
parentf9dd885cb6e6b70deff935689bb0dfb7d5b6a1a4 (diff)
downloadllvm-91bf0a073951aa1ca4c357967ed5aff891941785.zip
llvm-91bf0a073951aa1ca4c357967ed5aff891941785.tar.gz
llvm-91bf0a073951aa1ca4c357967ed5aff891941785.tar.bz2
[libc] Added static casts to fix implicit conversion warnings in 32-bit systems
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
Diffstat (limited to 'libc/src')
-rw-r--r--libc/src/__support/HashTable/randomness.h2
-rw-r--r--libc/src/__support/threads/thread.h10
-rw-r--r--libc/src/stdio/fopencookie.cpp8
-rw-r--r--libc/src/sys/auxv/linux/getauxval.cpp2
-rw-r--r--libc/src/sys/stat/linux/kernel_statx.h5
5 files changed, 14 insertions, 13 deletions
diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h
index 06d3e84..244dd41 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 1805b6f..9317452 100644
--- a/libc/src/__support/threads/thread.h
+++ b/libc/src/__support/threads/thread.h
@@ -102,11 +102,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
pid_t tid;
ThreadStyle style;
diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp
index 07be9a5..9f5694e 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 2ca894d..bfa6b23 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 f26f0b8..d0e223a 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,8 @@ 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;
}