[PATCH] D103772: [clang-cl] Reenable /Zc:twoPhase by default if targetting MSVC 2017 Update 3 or newer
Markus Böck via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 6 11:23:32 PDT 2021
zero9178 created this revision.
zero9178 added reviewers: rnk, hans, thakis.
Herald added a subscriber: dang.
zero9178 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch effectively relands https://reviews.llvm.org/D66394, which back then sadly had to be reverted due to build failures. The summary given in the commit is already great, but just to summarize: Since MSVC 2017 Update 3 (or 19.11, so beyond the 19.14 minimum that clang-cl supports), two phase template parsing had been enabled by default. This patch enables two phase lookup by default in clang-cl as well, when the MSVC compatibility version is 19.11 or higher.
The patch previously had to be reverted due to issues when executed with the GCC style driver and -fno-rtti as can be seen here https://bugs.chromium.org/p/chromium/issues/detail?id=996675. https://reviews.llvm.org/D103771, which this patch depends on, implements one of the resolutions given in the report, by defining _HAS_STATIC_RTTI. For older MSVC STL versions that had a missing guard in the functional header, -fno-rtti-data may have to passed instead of -fno-rtti, as soon as std::function is instantiated, regardless of whether two phase lookup is enabled or not.
Depends on https://reviews.llvm.org/D103771
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103772
Files:
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
Index: clang/test/Driver/cl-options.c
===================================================================
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -329,13 +329,19 @@
// We recognize -f[no-]delayed-template-parsing.
// /Zc:twoPhase[-] has the opposite meaning.
-// RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDDEFAULT %s
-// DELAYEDDEFAULT: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
-// RUN: %clang_cl -c /Zc:twoPhase- -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 -### -- %s 2>&1 | FileCheck -check-prefix=OLDDELAYEDDEFAULT %s
+// OLDDELAYEDDEFAULT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1911 -### -- %s 2>&1 | FileCheck -check-prefix=NEWDELAYEDDEFAULT %s
+// NEWDELAYEDDEFAULT-NOT: "-fdelayed-template-parsing"
+// RUN: %clang_cl -c -fmsc-version=1910 -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase- -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase- -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s
// DELAYEDON: "-fdelayed-template-parsing"
-// RUN: %clang_cl -c -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
-// RUN: %clang_cl -c /Zc:twoPhase -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1910 /Zc:twoPhase -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
+// RUN: %clang_cl -c -fmsc-version=1911 /Zc:twoPhase -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s
// DELAYEDOFF-NOT: "-fdelayed-template-parsing"
// RUN: %clang_cl -c -### /std:c++latest -- %s 2>&1 | FileCheck -check-prefix CHECK-LATEST-CHAR8_T %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6127,12 +6127,14 @@
!IsWindowsMSVC || IsMSVC2015Compatible))
CmdArgs.push_back("-fno-threadsafe-statics");
- // -fno-delayed-template-parsing is default, except when targeting MSVC.
- // Many old Windows SDK versions require this to parse.
- // FIXME: MSVC introduced /Zc:twoPhase- to disable this behavior in their
- // compiler. We should be able to disable this by default at some point.
+ // -fno-delayed-template-parsing is default, except when targeting MSVC
+ // earlier than MSVC 2017 15.3 (_MSC_VER 1911). Windows SDK versions
+ // 10.0.15063.0 (Creators Update or Redstone 2) and earlier require this to
+ // parse.
+ bool IsMSVCBefore2017Update3 = !MSVT.empty() && MSVT < VersionTuple(19, 11);
if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
- options::OPT_fno_delayed_template_parsing, IsWindowsMSVC))
+ options::OPT_fno_delayed_template_parsing,
+ IsMSVCBefore2017Update3))
CmdArgs.push_back("-fdelayed-template-parsing");
// -fgnu-keywords default varies depending on language; only pass if
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -6009,10 +6009,10 @@
def _SLASH_Zc_trigraphs_off : CLFlag<"Zc:trigraphs-">,
HelpText<"Disable trigraphs (default)">, Alias<fno_trigraphs>;
def _SLASH_Zc_twoPhase : CLFlag<"Zc:twoPhase">,
- HelpText<"Enable two-phase name lookup in templates">,
+ HelpText<"Enable two-phase name lookup in templates (default)">,
Alias<fno_delayed_template_parsing>;
def _SLASH_Zc_twoPhase_ : CLFlag<"Zc:twoPhase-">,
- HelpText<"Disable two-phase name lookup in templates (default)">,
+ HelpText<"Disable two-phase name lookup in templates">,
Alias<fdelayed_template_parsing>;
def _SLASH_Z7 : CLFlag<"Z7">,
HelpText<"Enable CodeView debug information in object files">;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
Windows Support
---------------
+- clang-cl now defaults to ``/Zc:twoPhase`` if targeting MSVC2017 update 3 or
+ later (``_MSC_VER`` >= 1911). This matches MSVC's behavior. Explicitly pass
+ ``/Zc:twoPhase-`` to restore the old behavior.
+
C Language Changes in Clang
---------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103772.350122.patch
Type: text/x-patch
Size: 4959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210606/60bf26ba/attachment-0001.bin>
More information about the cfe-commits
mailing list