[libc-commits] [libc] [libc][NFC] Fix minor RPC warnings (PR #192997)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed Apr 22 09:21:15 PDT 2026
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/192997
>From 03f64b1ebf07c964a41a3003bffada0d88e0e968 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 20 Apr 2026 10:13:13 -0500
Subject: [PATCH] [libc][NFC] Fix minor RPC warnings
Summary:
Fix some warnings that show up with strict warnings set, reduces noise
when used as a header onyl library in projects.
---
libc/shared/rpc.h | 4 ++--
libc/shared/rpc_server.h | 36 ++++++++++++++++++++++++------------
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/libc/shared/rpc.h b/libc/shared/rpc.h
index 5168e9fc60ba3..5bc518ab97af7 100644
--- a/libc/shared/rpc.h
+++ b/libc/shared/rpc.h
@@ -212,8 +212,8 @@ template <bool Invert> struct Process {
/// Given the current outbox and inbox values, wait until the inbox changes
/// to indicate that this thread owns the buffer element.
RPC_ATTRS void wait_for_ownership(uint64_t lane_mask, uint32_t index,
- uint32_t outbox, uint32_t in) {
- while (buffer_unavailable(in, outbox)) {
+ uint32_t out, uint32_t in) {
+ while (buffer_unavailable(in, out)) {
sleep_briefly();
in = load_inbox(lane_mask, index);
}
diff --git a/libc/shared/rpc_server.h b/libc/shared/rpc_server.h
index 175f91dd34b01..e77e38faf47af 100644
--- a/libc/shared/rpc_server.h
+++ b/libc/shared/rpc_server.h
@@ -301,10 +301,16 @@ template <typename ArgProvider> struct MicroParser {
SizeArgument size_pos = SizeArgument::finished;
};
+// The format strings were already checked and warned on the device side.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
+
// Dispatch helper that passes dynamic '*' width/precision values to fprintf.
template <typename T>
-inline int fprintf_with_stars(FILE *file, const char *fmt, int num_stars,
- int *star_vals, T val) {
+[[gnu::format(printf, 2, 0)]] inline int
+fprintf_with_stars(FILE *file, const char *fmt, int num_stars, int *star_vals,
+ T val) {
if (num_stars == 2)
return ::fprintf(file, fmt, star_vals[0], star_vals[1], val);
if (num_stars == 1)
@@ -410,6 +416,8 @@ inline int print_format(FILE *file, const char *fmt, StructArgList<packed> args,
return ret;
}
+#pragma GCC diagnostic pop
+
template <bool packed, uint32_t num_lanes>
inline void handle_printf(Server::Port &port, TempStorage &temp_storage) {
FILE *files[num_lanes] = {nullptr};
@@ -595,7 +603,7 @@ inline RPCStatus handle_port_impl(Server::Port &port) {
case LIBC_CLOSE_FILE: {
port.recv_and_send([&](Buffer *buffer, uint32_t) {
FILE *file = reinterpret_cast<FILE *>(buffer->data[0]);
- buffer->data[0] = ::fclose(file);
+ buffer->data[0] = static_cast<uint64_t>(::fclose(file));
});
break;
}
@@ -632,13 +640,15 @@ inline RPCStatus handle_port_impl(Server::Port &port) {
}
case LIBC_FEOF: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::feof(to_stream(buffer->data[0]));
+ buffer->data[0] =
+ static_cast<uint64_t>(::feof(to_stream(buffer->data[0])));
});
break;
}
case LIBC_FERROR: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::ferror(to_stream(buffer->data[0]));
+ buffer->data[0] =
+ static_cast<uint64_t>(::ferror(to_stream(buffer->data[0])));
});
break;
}
@@ -650,28 +660,30 @@ inline RPCStatus handle_port_impl(Server::Port &port) {
}
case LIBC_FSEEK: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::fseek(to_stream(buffer->data[0]),
- static_cast<long>(buffer->data[1]),
- static_cast<int>(buffer->data[2]));
+ buffer->data[0] = static_cast<uint64_t>(::fseek(
+ to_stream(buffer->data[0]), static_cast<long>(buffer->data[1]),
+ static_cast<int>(buffer->data[2])));
});
break;
}
case LIBC_FTELL: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::ftell(to_stream(buffer->data[0]));
+ buffer->data[0] =
+ static_cast<uint64_t>(::ftell(to_stream(buffer->data[0])));
});
break;
}
case LIBC_FFLUSH: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::fflush(to_stream(buffer->data[0]));
+ buffer->data[0] =
+ static_cast<uint64_t>(::fflush(to_stream(buffer->data[0])));
});
break;
}
case LIBC_UNGETC: {
port.recv_and_send([](Buffer *buffer, uint32_t) {
- buffer->data[0] = ::ungetc(static_cast<int>(buffer->data[0]),
- to_stream(buffer->data[1]));
+ buffer->data[0] = static_cast<uint64_t>(::ungetc(
+ static_cast<int>(buffer->data[0]), to_stream(buffer->data[1])));
});
break;
}
More information about the libc-commits
mailing list