[PATCH] D63817: [clangd] No longer getting template instantiations from header files in Main AST.
Johan Vikström via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 26 08:37:40 PDT 2019
jvikstrom updated this revision to Diff 206684.
jvikstrom marked 2 inline comments as done.
jvikstrom added a comment.
Using isInMainFile instead
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63817/new/
https://reviews.llvm.org/D63817
Files:
clang-tools-extra/clangd/ClangdUnit.cpp
clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -83,6 +83,26 @@
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"(
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -67,8 +67,10 @@
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.
if (isa<ObjCMethodDecl>(D))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63817.206684.patch
Type: text/x-patch
Size: 1436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190626/b44728e7/attachment.bin>
More information about the cfe-commits
mailing list