[PATCH] D127641: [clang-cl][MSVC] Add default /Zc conformance arguments

Stephen Long via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 15:58:15 PDT 2022


steplong updated this revision to Diff 436592.
steplong added a comment.

- Ignore /Zc:wchar_t


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127641/new/

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
@@ -6514,7 +6514,7 @@
 def _SLASH_Zc_twoPhase_ : CLFlag<"Zc:twoPhase-">,
   HelpText<"Disable two-phase name lookup in templates (default)">,
   Alias<fdelayed_template_parsing>;
-def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
+def _SLASH_Zc_wchar_t : CLIgnoredFlag<"Zc:wchar_t">,
   HelpText<"Enable C++ builtin type wchar_t (default)">;
 def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
   HelpText<"Disable C++ builtin type wchar_t">;
@@ -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">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127641.436592.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220613/de1e86e2/attachment.bin>


More information about the cfe-commits mailing list