[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 07:45:32 PDT 2022


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">;


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


More information about the cfe-commits mailing list