[llvm] [gn] Add "/Zc:preprocessor" build flag on windows (PR #108252)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 10:11:26 PDT 2024


https://github.com/GkvJwa created https://github.com/llvm/llvm-project/pull/108252

Add ```/Zc:preprocessor``` to fix the ```__VA_ARGS__``` expansion error encountered when building with gn

```
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(43): warning C4003: not enough arguments for function-like macro invocation 'LLVM_MAKE_OPT_ID'
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(44): warning C4003: not enough arguments for function-like macro invocation 'LLVM_MAKE_OPT_ID'
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(44): error C2365: '`anonymous-namespace'::OPT_': redefinition; previous definition was 'enumerator'
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(43): note: see declaration of '`anonymous-namespace'::OPT_'
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(45): warning C4003: not enough arguments for function-like macro invocation 'LLVM_MAKE_OPT_ID'
gen\llvm\lib\ToolDrivers\llvm-dlltool\Options.inc(45): error C2365: '`anonymous-namespace'::OPT_': redefinition; previous definition was 'enumerator'
```

>From 8f9a82e8ad1ab67c01dd7518b8ed92ad2e2beeb9 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Thu, 12 Sep 2024 01:05:15 +0800
Subject: [PATCH] [gn] Add /Zc:preprocessor on windows

---
 llvm/utils/gn/build/BUILD.gn | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index 1ccaefdc21c822..11d28f6be6bce9 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -183,6 +183,9 @@ config("compiler_defaults") {
     cflags += [ "/EHs-c-" ]
     cflags_cc += [ "/std:c++17" ]
 
+    # expand __VA_ARGS__ in "OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__)"
+    cflags += [ "/Zc:preprocessor" ]
+
     # cl.exe doesn't set __cplusplus correctly by default.
     # clang-cl gets it right by default, so don't needlessly add the flag there.
     if (!is_clang) {



More information about the llvm-commits mailing list