steplong created this revision. Herald added a project: All. steplong requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This patch doesn't turn on all the "on by default" /Zc arguments, but this should be a good enough starting point. https://docs.microsoft.com/en-us/cpp/build/reference/zc-conformance?view=msvc-170 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D127641 Files: clang/include/clang/Driver/Options.td clang/test/Driver/cl-zc.cpp clang/tools/driver/driver.cpp Index: clang/tools/driver/driver.cpp =================================================================== --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -234,6 +234,25 @@ } } +static void insertDefaultClangCLZcConformanceArgs( + SmallVectorImpl<const char *> &ArgVector) { + // Put the /Zc arguments at the start of argument list so that arguments + // specified on + // the command line could override them. Avoid putting them at index 0, as an + // option + // like '-cc1' must remain the first. + int InsertionPoint = 0; + if (ArgVector.size() > 0) + ++InsertionPoint; + + const char *arr[] = { + "/Zc:auto", "/Zc:forScope", "/Zc:implicitNoexcept", + "/Zc:sizedDealloc", "/Zc:threadSafeInit", "/Zc:wchar_t"}; + + ArgVector.insert(ArgVector.begin() + InsertionPoint, std::begin(arr), + std::end(arr)); +} + static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver, SmallVectorImpl<const char *> &Opts) { llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts); @@ -473,6 +492,9 @@ insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings); + if (ClangCLMode) + insertDefaultClangCLZcConformanceArgs(Args); + SetBackdoorDriverOutputsFromEnvVars(TheDriver); if (!UseNewCC1Process) { Index: clang/test/Driver/cl-zc.cpp =================================================================== --- clang/test/Driver/cl-zc.cpp +++ clang/test/Driver/cl-zc.cpp @@ -1,6 +1,9 @@ // 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. +// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULT %s +// DEFAULT: "-fsized-deallocation" + // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=TRIGRAPHS-DEFAULT %s // cc1 will disable trigraphs for -fms-compatibility as long as -ftrigraphs // isn't explicitly passed. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -6701,6 +6701,7 @@ def _SLASH_Wv_ : CLIgnoredJoined<"Wv">; def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">; def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">; +def _SLASH_Zc_implicitNoexcept : CLIgnoredFlag<"Zc:implicitNoexcept">; def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">; def _SLASH_Zc_inline : CLIgnoredFlag<"Zc:inline">; def _SLASH_Zc_rvalueCast : CLIgnoredFlag<"Zc:rvalueCast">;
Index: clang/tools/driver/driver.cpp =================================================================== --- clang/tools/driver/driver.cpp +++ clang/tools/driver/driver.cpp @@ -234,6 +234,25 @@ } } +static void insertDefaultClangCLZcConformanceArgs( + SmallVectorImpl<const char *> &ArgVector) { + // Put the /Zc arguments at the start of argument list so that arguments + // specified on + // the command line could override them. Avoid putting them at index 0, as an + // option + // like '-cc1' must remain the first. + int InsertionPoint = 0; + if (ArgVector.size() > 0) + ++InsertionPoint; + + const char *arr[] = { + "/Zc:auto", "/Zc:forScope", "/Zc:implicitNoexcept", + "/Zc:sizedDealloc", "/Zc:threadSafeInit", "/Zc:wchar_t"}; + + ArgVector.insert(ArgVector.begin() + InsertionPoint, std::begin(arr), + std::end(arr)); +} + static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver, SmallVectorImpl<const char *> &Opts) { llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts); @@ -473,6 +492,9 @@ insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings); + if (ClangCLMode) + insertDefaultClangCLZcConformanceArgs(Args); + SetBackdoorDriverOutputsFromEnvVars(TheDriver); if (!UseNewCC1Process) { Index: clang/test/Driver/cl-zc.cpp =================================================================== --- clang/test/Driver/cl-zc.cpp +++ clang/test/Driver/cl-zc.cpp @@ -1,6 +1,9 @@ // 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. +// RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULT %s +// DEFAULT: "-fsized-deallocation" + // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=TRIGRAPHS-DEFAULT %s // cc1 will disable trigraphs for -fms-compatibility as long as -ftrigraphs // isn't explicitly passed. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -6701,6 +6701,7 @@ def _SLASH_Wv_ : CLIgnoredJoined<"Wv">; def _SLASH_Zc___cplusplus : CLIgnoredFlag<"Zc:__cplusplus">; def _SLASH_Zc_auto : CLIgnoredFlag<"Zc:auto">; +def _SLASH_Zc_implicitNoexcept : CLIgnoredFlag<"Zc:implicitNoexcept">; def _SLASH_Zc_forScope : CLIgnoredFlag<"Zc:forScope">; def _SLASH_Zc_inline : CLIgnoredFlag<"Zc:inline">; def _SLASH_Zc_rvalueCast : CLIgnoredFlag<"Zc:rvalueCast">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits