[PATCH] D99664: Force utf8 to avoid compilation error on Windows with non-english code page
Cloud Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 15 08:35:52 PDT 2021
cloudhan updated this revision to Diff 337780.
cloudhan removed a subscriber: llvm-commits.
cloudhan added a comment.
Let's see what happens if we do not use the walkaround.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99664/new/
https://reviews.llvm.org/D99664
Files:
compiler-rt/lib/sanitizer_common/traceloggingprovider_utf8.h
llvm/CMakeLists.txt
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -594,6 +594,8 @@
if (BUILD_SHARED_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS options is not supported on Windows.")
endif()
+ # Force MSVC to read code as UTF-8.
+ add_compile_options(/utf-8)
else()
option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin only)" OFF)
Index: compiler-rt/lib/sanitizer_common/traceloggingprovider_utf8.h
===================================================================
--- /dev/null
+++ compiler-rt/lib/sanitizer_common/traceloggingprovider_utf8.h
@@ -0,0 +1,46 @@
+//===-- traceloggingprovider_utf8.h -----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Windows-specific walkaround.
+//
+//===----------------------------------------------------------------------===//
+#ifndef TRACELOGGINGPROVIDER_UTF8_H
+#define TRACELOGGINGPROVIDER_UTF8_H
+
+// See:
+// https://developercommunity.visualstudio.com/t/traceloggingproviderh-is-incompatible-with-utf-8/85934
+// Include this header instead of TraceLoggingProvider.h to fix this issue.
+
+#if defined(_WIN32)
+#include <TraceLoggingProvider.h>
+
+#ifdef _TlgPragmaUtf8Begin
+#undef _TlgPragmaUtf8Begin
+#define _TlgPragmaUtf8Begin
+#endif
+
+#ifdef _TlgPragmaUtf8End
+#undef _TlgPragmaUtf8End
+#define _TlgPragmaUtf8End
+#endif
+
+// Different versions of TraceLoggingProvider.h contain different macro
+// variable names for the utf8 begin and end, and we need to cover the lower
+// case version as well.
+#ifdef _tlgPragmaUtf8Begin
+#undef _tlgPragmaUtf8Begin
+#define _tlgPragmaUtf8Begin
+#endif
+
+#ifdef _tlgPragmaUtf8End
+#undef _tlgPragmaUtf8End
+#define _tlgPragmaUtf8End
+#endif
+
+#endif // _WIN32
+#endif // TRACELOGGINGPROVIDER_UTF8_H
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99664.337780.patch
Type: text/x-patch
Size: 2243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210415/0b0c358a/attachment.bin>
More information about the llvm-commits
mailing list