Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -7327,6 +7327,14 @@ CmdArgs.push_back("--dependent-lib=oldnames"); } + // 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 + CmdArgs.push_back("-D_MSVC_EXECUTION_CHARACTER_SET=65001"); + if (Arg *ShowIncludes = Args.getLastArg(options::OPT__SLASH_showIncludes, options::OPT__SLASH_showIncludes_user)) { Index: clang/test/Driver/cl-execution-character-set.c =================================================================== --- /dev/null +++ clang/test/Driver/cl-execution-character-set.c @@ -0,0 +1,7 @@ +// Note: %s must be preceded by --, otherwise it may be interpreted as a +// command-line option, e.g. on Mac where %s is commonly under /Users. + +// Only UTF-8 is currently supported, which has the Windows Code +// Page Identifier 65001 +// RUN: %clang_cl -### -- %s 2>&1 | FileCheck %s +// CHECK: -D_MSVC_EXECUTION_CHARACTER_SET=65001