[PR52549][clang-cl] Predefine _MSVC_EXECUTION_CHARACTER_SET
authorMarkus Böck <markus.boeck02@gmail.com>
Tue, 30 Nov 2021 08:13:02 +0000 (09:13 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Tue, 30 Nov 2021 08:13:22 +0000 (09:13 +0100)
Since VS 2022 17.1 MSVC predefines _MSVC_EXECUTION_CHARACTER_SET to inform the users of the execution character set defined at compile time. The value the macro expands to is a Windows Code Page Identifier which are documented here: https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers

As clang currently only supports UTF-8 it is defined as 65001. If clang-cl were to support a different execution character set in the future we'd have to change the value.

Fixes https://bugs.llvm.org/show_bug.cgi?id=52549

Differential Revision: https://reviews.llvm.org/D114576

clang/lib/Basic/Targets/OSTargets.cpp
clang/test/Preprocessor/init.c

index 7cd4a51901205026868ada3858a4d68ebad41655..4d9a462b51366c2f55b2c550252467c096e92449 100644 (file)
@@ -201,6 +201,14 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
   }
 
   Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+
+  // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+  // users of the execution character set defined at compile time.
+  // The value given is the Windows Code Page Identifier:
+  // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+  //
+  // Clang currently only supports UTF-8, so we'll use 65001
+  Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
 }
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
index 8bbfe85b9ba7448a576cf5ec0eb979844caa6401..52c33d9b8b7a558dc0b4f47ea94b6d32d1a4b335 100644 (file)
 // MSEXT:#define _INTEGRAL_MAX_BITS 64
 // MSEXT-NOT:#define _NATIVE_WCHAR_T_DEFINED 1
 // MSEXT-NOT:#define _WCHAR_T_DEFINED 1
+// MSEXT:#define _MSVC_EXECUTION_CHARACTER_SET 65001
 //
 //
 // RUN: %clang_cc1 -x c++ -fms-extensions -triple i686-pc-win32 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix MSEXT-CXX %s