[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
Wed Apr 14 04:48:22 PDT 2021


cloudhan updated this revision to Diff 337410.
cloudhan added a comment.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.

Let's try this patch


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/sanitizer_win.cpp
  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,43 @@
+//===-- 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.
+
+#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  // TRACELOGGINGPROVIDER_UTF8_H
Index: compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
@@ -32,7 +32,7 @@
 #pragma comment(lib, "psapi")
 #endif
 #if SANITIZER_WIN_TRACE
-#include <traceloggingprovider.h>
+#include "traceloggingprovider_utf8.h"
 //  Windows trace logging provider init
 #pragma comment(lib, "advapi32.lib")
 TRACELOGGING_DECLARE_PROVIDER(g_asan_provider);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99664.337410.patch
Type: text/x-patch
Size: 2729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210414/059eeda2/attachment.bin>


More information about the llvm-commits mailing list