https://github.com/youngd007 created 
https://github.com/llvm/llvm-project/pull/213045

Several Windows headers/TUs unconditionally `#define WIN32_LEAN_AND_MEAN`. When 
a build predefines the macro on the compiler command line (e.g. a toolchain 
that passes -DWIN32_LEAN_AND_MEAN, which clang treats as `#define 
WIN32_LEAN_AND_MEAN 1`), the differing token lists trigger -Wmacro-redefined, 
which becomes a hard error under -Werror.

Guard the definitions with #ifndef, matching the adjacent NOMINMAX handling and 
the existing pattern in llvm/lib/Support/rpmalloc/rpmalloc.c. The macro is only 
a presence flag, so keeping an externally-provided definition is correct.

Sites guarded:
  llvm/include/llvm/Support/Windows/WindowsSupport.h
  llvm/lib/WindowsDriver/MSVCPaths.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  lldb/include/lldb/Host/windows/windows.h

Meta ran into this internally building lldb on window after a sync with 
upstream from July commit, so adding guards would allow us to drop a workaround 
of ignoring the duplicate defines.

Error:
llvm\include\llvm/Support/Windows/WindowsSupport.h(29,9): error: 
'WIN32_LEAN_AND_MEAN' macro redefined [-Werror,-Wmacro-redefined]
   29 | #define WIN32_LEAN_AND_MEAN
      |         ^
<command line>(10,9): note: previous definition is here
   10 | #define WIN32_LEAN_AND_MEAN 1
      |         ^
1 error generated.

>From 13dcd6e0dd53af694baa06bbfee299a34b3cdacb Mon Sep 17 00:00:00 2001
From: David Young <[email protected]>
Date: Thu, 30 Jul 2026 08:07:05 -0700
Subject: [PATCH] [Support][Driver][LLDB] Guard WIN32_LEAN_AND_MEAN definitions
 with #ifndef

Several Windows headers/TUs unconditionally `#define WIN32_LEAN_AND_MEAN`.
When a build predefines the macro on the compiler command line (e.g. a
toolchain that passes -DWIN32_LEAN_AND_MEAN, which clang treats as
`#define WIN32_LEAN_AND_MEAN 1`), the differing token lists trigger
-Wmacro-redefined, which becomes a hard error under -Werror.

Guard the definitions with #ifndef, matching the adjacent NOMINMAX handling
and the existing pattern in llvm/lib/Support/rpmalloc/rpmalloc.c. The macro
is only a presence flag, so keeping an externally-provided definition is
correct.

Sites guarded:
  llvm/include/llvm/Support/Windows/WindowsSupport.h
  llvm/lib/WindowsDriver/MSVCPaths.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  lldb/include/lldb/Host/windows/windows.h
---
 clang/lib/Driver/ToolChains/MSVC.cpp               | 2 ++
 lldb/include/lldb/Host/windows/windows.h           | 2 ++
 llvm/include/llvm/Support/Windows/WindowsSupport.h | 2 ++
 llvm/lib/WindowsDriver/MSVCPaths.cpp               | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 07ad9215fc029..07cf2ee2122f3 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -26,7 +26,9 @@
 #include <cstdio>
 
 #ifdef _WIN32
+  #ifndef WIN32_LEAN_AND_MEAN
   #define WIN32_LEAN_AND_MEAN
+  #endif
   #define NOGDI
   #ifndef NOMINMAX
     #define NOMINMAX
diff --git a/lldb/include/lldb/Host/windows/windows.h 
b/lldb/include/lldb/Host/windows/windows.h
index d53d4b9967268..bfaafdc952585 100644
--- a/lldb/include/lldb/Host/windows/windows.h
+++ b/lldb/include/lldb/Host/windows/windows.h
@@ -12,7 +12,9 @@
 #define NTDDI_VERSION NTDDI_VISTA
 #undef _WIN32_WINNT // undef a previous definition to avoid warning
 #define _WIN32_WINNT _WIN32_WINNT_VISTA
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
+#endif
 #define NOGDI
 #undef NOMINMAX // undef a previous definition to avoid warning
 #define NOMINMAX
diff --git a/llvm/include/llvm/Support/Windows/WindowsSupport.h 
b/llvm/include/llvm/Support/Windows/WindowsSupport.h
index 50a2540dba687..fe475f0b629ce 100644
--- a/llvm/include/llvm/Support/Windows/WindowsSupport.h
+++ b/llvm/include/llvm/Support/Windows/WindowsSupport.h
@@ -26,7 +26,9 @@
 
 // Require at least Windows 7 API.
 #define _WIN32_WINNT 0x0601
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
+#endif
 #ifndef NOMINMAX
 #define NOMINMAX
 #endif
diff --git a/llvm/lib/WindowsDriver/MSVCPaths.cpp 
b/llvm/lib/WindowsDriver/MSVCPaths.cpp
index 09468dab10260..3092ee2fbf5b9 100644
--- a/llvm/lib/WindowsDriver/MSVCPaths.cpp
+++ b/llvm/lib/WindowsDriver/MSVCPaths.cpp
@@ -27,7 +27,9 @@
 #endif
 
 #ifdef _WIN32
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
+#endif
 #define NOGDI
 #ifndef NOMINMAX
 #define NOMINMAX

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to