This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Reenable /Zc:twoPhase by default if targetting MSVC 2017 Update 3 or newer
AbandonedPublic

Authored by zero9178 on Jun 6 2021, 11:23 AM.

Details

Reviewers
rnk
hans
thakis
Summary

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

Diff Detail

Event Timeline

zero9178 created this revision.Jun 6 2021, 11:23 AM
zero9178 requested review of this revision.Jun 6 2021, 11:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2021, 11:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
zero9178 updated this revision to Diff 350125.Jun 6 2021, 12:02 PM

Rebased onto main

It was reverted due to build failures, but it didn't reland because it's not the default in cl.exe after all. So we shouldn't make it the default in clang-cl either.

zero9178 abandoned this revision.Jun 7 2021, 4:27 AM

Thanks for the info, seems like I was mislead after testing it again.

rnk added a comment.Jun 14 2021, 12:34 PM

If we look back at the original intention of our MSVC compatibility work, we tried to accept as much invalid code as necessary to parse "system headers". System headers were widely interpreted to bethe MSVC STL, ATL, and the Windows SDK. So, even if MSVC defaults to delayed template parsing, if system headers parse with /Zc:twoPhase enabled, maybe we could pick a different default. We'd document the behavior change, of course. Delayed template parsing is an ongoing source of bugs (https://llvm.org/pr50676) and maintenance overhead, so it would be worth diverging from MSVC a bit if possible.

So... maybe we should go ahead with this anyway. As I understand it, all these headers parse correctly in the presence of /Zc:twoPhase, and the RTTI issue has been resolved (?), so we should be OK. I think.