[libc-commits] [libc] [libc][NFC] Fix minor RPC warnings (PR #192997)

via libc-commits libc-commits at lists.llvm.org
Mon Apr 20 08:15:55 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

Summary:
Fix some warnings that show up with strict warnings set, reduces noise
when used as a header onyl library in projects.


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


2 Files Affected:

- (modified) libc/shared/rpc.h (+2-2) 
- (modified) libc/shared/rpc_server.h (+24-12) 


``````````diff
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;
   }

``````````

</details>


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


More information about the libc-commits mailing list