[libc-commits] [libc] [libc] Silence `-Winconsistent-dllimport` on Windows (PR #191560)

Alexandre Ganea via libc-commits libc-commits at lists.llvm.org
Fri Apr 10 15:52:55 PDT 2026


https://github.com/aganea created https://github.com/llvm/llvm-project/pull/191560

On non-GPU targets, malloc/free are already declared (with `dllimport` on Windows) via the system headers included by `rpc_util.h`. Re-declaring them without `dllimport` triggers `-Winconsistent-dllimport` on Windows.

>From 415593e90c245518bc7c3092c1fdceadc26a3193 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <aganea at havenstudios.com>
Date: Fri, 10 Apr 2026 18:16:21 -0400
Subject: [PATCH] [libc] Silence `-Winconsistent-dllimport` on Windows

On non-GPU targets, malloc/free are already declared (with dllimport on
Windows) via the system headers included by rpc_util.h. Re-declaring them
without dllimport triggers `-Winconsistent-dllimport` on Windows.
---
 libc/shared/rpc_dispatch.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libc/shared/rpc_dispatch.h b/libc/shared/rpc_dispatch.h
index dcc54852b40bc..5603eb232b149 100644
--- a/libc/shared/rpc_dispatch.h
+++ b/libc/shared/rpc_dispatch.h
@@ -12,12 +12,20 @@
 #include "rpc.h"
 #include "rpc_util.h"
 
+#ifndef RPC_TARGET_IS_GPU
+#include <cstdlib>
+#endif
+
 namespace rpc {
 namespace {
 
-// Forward declarations needed for the server, we assume these are present.
+// On non-GPU targets, malloc/free are already declared (with dllimport on
+// Windows) via the system headers included by rpc_util.h. Re-declaring them
+// without dllimport triggers -Winconsistent-dllimport on Windows.
+#ifdef RPC_TARGET_IS_GPU
 extern "C" void *malloc(__SIZE_TYPE__);
 extern "C" void free(void *);
+#endif
 
 // Traits to convert between a tuple and binary representation of an argument
 // list.



More information about the libc-commits mailing list