-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ms] Enable /Zc:twoPhase by default if fmsc-version is 1911+ #42377
Comments
Maybe this does it. Need to run and update tests, and need to check that this correctly picks up the version of system cl.exe if no explicit -fmsc-version flag is passed. diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 690d4fa3fa4..c0f914bf989 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4883,12 +4883,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
!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 |
patch Still need to verify this does the right thing without an explicit -fmsc-version flag. |
This landed and then got reverted, but I'd love to see it come back. :) To reland, we need to make sure check-asan passes on Windows with the header from MSVC 14.16.27023, either by raising our msvc compat check, or by tweaking the -fno-rtti / -fno-rtti-data settings somewhere. |
This came up again last June: Delayed template parsing continues to cause issues for AST consumers such as clang-tidy. The effect is that the body of a function template is simply a null pointer, which usually results in analyzer crashes. See this recent Discourse thread: So, I think it's worth attempting to make this change again. |
I've been bad about updating this. Here's an update of things that happened (or didn't happen) in the last 2.5 years: Most importantly, the premise is wrong. MSVC does not enable So just based on cl.exe not doing it by default, clang-cl should neither I think. There's some discussion of the revert at https://bugs.chromium.org/p/chromium/issues/detail?id=996675. It also mentions a few issues:
So I think most things that we realistically want to do here are probably done. Unless we want to deviate from cl.exe behavior, but I'm not sure that's a good idea. |
I had some text addressing the angle of MSVC compatibility in the discourse thread:
Basically, I hear the concern, but I still think we should do it anyway. It's true, the premise of the issue summary is wrong, but users will be better off if we sunset this error prone compatibility mode now. |
I don't have an opinion on changing the default. (Would you want to change just the default of Chrome builds with |
I only think we should change the default for The V8 thing is interesting, since it suggests that various Windows SDK headers (DbgModel.h) still don't compile with I think the next step here is to look at the _HAS_STATIC_RTTI thing, so that |
TIL that (I mostly just wanted to mention that with C++20, MSVC has two-phase lookup by default now.) |
Extended Description
https://docs.microsoft.com/en-us/cpp/build/reference/zc-twophase?view=vs-2019 claims that cl.exe enables /Zc:twoPhase by default as of Visual Studio 2017 version 15.3, so we should change clang-cl to behave like that as well.
15.3+ seems to correspond to _MSC_VER 1911+.
The text was updated successfully, but these errors were encountered: