[clang] [lldb] [llvm] [Support][Driver][LLDB] Guard WIN32_LEAN_AND_MEAN definitions with #ifndef (PR #213045)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 30 08:25:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: David Young (youngd007)

<details>
<summary>Changes</summary>

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.

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


4 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MSVC.cpp (+2) 
- (modified) lldb/include/lldb/Host/windows/windows.h (+2) 
- (modified) llvm/include/llvm/Support/Windows/WindowsSupport.h (+2) 
- (modified) llvm/lib/WindowsDriver/MSVCPaths.cpp (+2) 


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

``````````

</details>


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


More information about the cfe-commits mailing list