[clang-tools-extra] 6d7637d - [clangd] Disable delayed template parsing in the main file
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 26 05:37:29 PDT 2020
Author: Sam McCall
Date: 2020-04-26T14:29:38+02:00
New Revision: 6d7637dc460a3602d725eca8698fa0ecd920031b
URL: https://github.com/llvm/llvm-project/commit/6d7637dc460a3602d725eca8698fa0ecd920031b
DIFF: https://github.com/llvm/llvm-project/commit/6d7637dc460a3602d725eca8698fa0ecd920031b.diff
LOG: [clangd] Disable delayed template parsing in the main file
Summary:
This is on by default in windows and breaks most features in template bodies.
We'd already disabled it in code completion, now disable it for building ASTs.
Potential regressions:
- we may give spurious errors where files with templates relying on delayed
parsing are directly opened
- we may misparse such template bodies that are instantiated (and therefore
*were* previously parsed)
Still *probably* a win overall. Avoiding the regressions entirely would be
substantial work and we don't have plans for it now.
Fixes https://github.com/clangd/clangd/issues/302 (again)
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78848
Added:
Modified:
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index fc631da3a317..bf09b14b1427 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -256,6 +256,9 @@ ParsedAST::build(llvm::StringRef Version,
// Recovery expression currently only works for C++.
if (CI->getLangOpts()->CPlusPlus)
CI->getLangOpts()->RecoveryAST = Opts.BuildRecoveryAST;
+ // This is on-by-default in windows to allow parsing SDK headers, but it
+ // breaks many features. Disable it for the main-file (not preamble).
+ CI->getLangOpts()->DelayedTemplateParsing = false;
StoreDiags ASTDiags;
std::string Content = std::string(Buffer->getBuffer());
diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index 1636e8f42183..a2bc996be4f1 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -175,6 +175,17 @@ TEST(ParsedASTTest,
AllOf(DeclNamed("foo"), WithTemplateArgs("<bool>"))}));
}
+TEST(ParsedASTTest, IgnoresDelayedTemplateParsing) {
+ auto TU = TestTU::withCode(R"cpp(
+ template <typename T> void xxx() {
+ int yyy = 0;
+ }
+ )cpp");
+ TU.ExtraArgs.push_back("-fdelayed-template-parsing");
+ auto AST = TU.build();
+ EXPECT_EQ(Decl::Var, findUnqualifiedDecl(AST, "yyy").getKind());
+}
+
TEST(ParsedASTTest, TokensAfterPreamble) {
TestTU TU;
TU.AdditionalFiles["foo.h"] = R"(
More information about the cfe-commits
mailing list