diff options
| author | Johan Vikstrom <jvikstrom@google.com> | 2019-07-01 11:49:01 +0000 | 
|---|---|---|
| committer | Johan Vikstrom <jvikstrom@google.com> | 2019-07-01 11:49:01 +0000 | 
| commit | 881aab4dc3dfbf8109f55b67f0db86b3a36a9bc7 (patch) | |
| tree | 590c1915fb454c4081b9b272bbbc6594ba47f69c | |
| parent | 92e78b7bedb987b1fcb7f25207df8a7381d9d7a6 (diff) | |
| download | bcm5719-llvm-881aab4dc3dfbf8109f55b67f0db86b3a36a9bc7.tar.gz bcm5719-llvm-881aab4dc3dfbf8109f55b67f0db86b3a36a9bc7.zip  | |
[clangd] No longer getting template instantiations from header files in Main AST.
Previous implementation to filter decls not in the main file did not
work in the case where a template was instantiated from a header in the
main file. It would than include that function/class in topLevelDecls.
Differential Revision: https://reviews.llvm.org/D63817
llvm-svn: 364747
| -rw-r--r-- | clang-tools-extra/clangd/ClangdUnit.cpp | 3 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp | 20 | 
2 files changed, 22 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index 4b272a90ba3..3beec0aa228 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -67,7 +67,8 @@ public:    bool HandleTopLevelDecl(DeclGroupRef DG) override {      for (Decl *D : DG) { -      if (D->isFromASTFile()) +      auto &SM = D->getASTContext().getSourceManager(); +      if (!SM.isWrittenInMainFile(SM.getExpansionLoc(D->getLocation())))          continue;        // ObjCMethodDecl are not actually top-level decls. diff --git a/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp b/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp index bfeb1c83e8b..3b5920e947d 100644 --- a/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp @@ -83,6 +83,26 @@ TEST(ClangdUnitTest, TopLevelDecls) {    EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));  } +TEST(ClangdUnitTest, DoesNotGetIncludedTopDecls) { +  TestTU TU; +  TU.HeaderCode = R"cpp( +    #define LL void foo(){} +    template<class T> +    struct H { +      H() {} +      LL +    }; +  )cpp"; +  TU.Code = R"cpp( +    int main() { +      H<int> h; +      h.foo(); +    } +  )cpp"; +  auto AST = TU.build(); +  EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main"))); +} +  TEST(ClangdUnitTest, TokensAfterPreamble) {    TestTU TU;    TU.AdditionalFiles["foo.h"] = R"(  | 

