[PATCH] D80433: [clang-tblgen][CommandLine][ManagedStatic] Fix build errors with clang-tblgen in Debug mode using MSVC 2019 v16.6

Denys Petrov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 22 05:51:23 PDT 2020


ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: rnk, lattner, stoklund, bkramer.
ASDenysPetrov added projects: LLVM, clang.
Herald added a subscriber: llvm-commits.
ASDenysPetrov updated this revision to Diff 265714.
ASDenysPetrov added a comment.

@lattner, @rnk, @stoklund, @bkramer,	please, review the change.


I'm using Windows. After updating **MSVS19** from **v16.4** to **v16.6** I faced with a build errors compiling in Debug mode.
It complains on //clang-tblgen.exe// and //llvm-tblgen.exe// cmd line args, e.g.

  D:\llvm-project\buildvs\Debug\bin>clang-tblgen.exe --help
  clang-tblgen.exe: Unknown command line argument '--help'.  Try: 'clang-tblgen.exe --help'
  clang-tblgen.exe: Did you mean '--color'?

After some debugging it turned out that VS compiler had a bug. It dynamically creates an object with constexpr ctor in Debug mode. This bug has been fixed in VS2019 v16.5.
https://developercommunity.visualstudio.com/content/problem/262083/compiler-emits-dynamic-initializer-for-variable-wi.html
But a workaround was implemented for that and everithing works until v16.5 comes.
The workaround became irrelevant since v16.5 and caused build errors.
So I disabled the workaround for VS2019 v16.5 and higher.

Now the build compiles without errors and works correctly.


https://reviews.llvm.org/D80433

Files:
  llvm/include/llvm/Support/ManagedStatic.h


Index: llvm/include/llvm/Support/ManagedStatic.h
===================================================================
--- llvm/include/llvm/Support/ManagedStatic.h
+++ llvm/include/llvm/Support/ManagedStatic.h
@@ -40,8 +40,11 @@
 // constexpr, a dynamic initializer may be emitted depending on optimization
 // settings. For the affected versions of MSVC, use the old linker
 // initialization pattern of not providing a constructor and leaving the fields
-// uninitialized.
-#if !defined(_MSC_VER) || defined(__clang__)
+// uninitialized. This bug was fixed in VS2019 ver16.5
+// (https://developercommunity.visualstudio.com/content/problem/262083/compiler-emits-dynamic-initializer-for-variable-wi.html).
+// Check MSVC version here
+// (https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?redirectedfrom=MSDN&view=vs-2019).
+#if (defined(_MSC_VER) && (_MSC_VER >= 1925)) || defined(__clang__)
 #define LLVM_USE_CONSTEXPR_CTOR
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80433.265714.patch
Type: text/x-patch
Size: 954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200522/33df6145/attachment-0001.bin>


More information about the llvm-commits mailing list