diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2019-04-15 14:38:46 +0000 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2019-04-15 14:38:46 +0000 |
commit | bb6cd8254c2497e744a6774174a6c11636ba9d25 (patch) | |
tree | 7a1346bd4164df12aa364fbdbf1a7db90885159b | |
parent | 5e165fba3acdb15bc7bb8ef8d44a2182ddda5e71 (diff) | |
download | bcm5719-llvm-bb6cd8254c2497e744a6774174a6c11636ba9d25.tar.gz bcm5719-llvm-bb6cd8254c2497e744a6774174a6c11636ba9d25.zip |
[clangd] Fallback to OrigD when SLoc is invalid
Summary:
Some implicit/built-in decls lack the source location
information. Fallback to OrigD that we've seen in the source code
instead of the canonical one in those cases.
Reviewers: sammccall
Subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric, ilya-biryukov
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60689
llvm-svn: 358413
-rw-r--r-- | clang-tools-extra/clangd/index/SymbolCollector.cpp | 6 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index a37ccd22f99..142e0f4cefe 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -285,6 +285,11 @@ bool SymbolCollector::handleDeclOccurence( assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set."); assert(CompletionAllocator && CompletionTUInfo); assert(ASTNode.OrigD); + // Indexing API puts cannonical decl into D, which might not have a valid + // source location for implicit/built-in decls. Fallback to original decl in + // such cases. + if (D->getLocation().isInvalid()) + D = ASTNode.OrigD; // If OrigD is an declaration associated with a friend declaration and it's // not a definition, skip it. Note that OrigD is the occurrence that the // collector is currently visiting. @@ -540,6 +545,7 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID, S.SymInfo = index::getSymbolInfo(&ND); std::string FileURI; auto Loc = findNameLoc(&ND); + assert(Loc.isValid() && "Invalid source location for NamedDecl"); // FIXME: use the result to filter out symbols. shouldIndexFile(SM, SM.getFileID(Loc), Opts, &FilesToIndexCache); if (auto DeclLoc = diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp index 5b9e55353ca..bd46cc18520 100644 --- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp +++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp @@ -1241,6 +1241,14 @@ TEST_F(SymbolCollectorTest, CBuiltins) { EXPECT_THAT(Symbols, Contains(QName("printf"))); } +TEST_F(SymbolCollectorTest, InvalidSourceLoc) { + const char *Header = R"( + void operator delete(void*) + __attribute__((__externally_visible__));)"; + runSymbolCollector(Header, /**/ ""); + EXPECT_THAT(Symbols, Contains(QName("operator delete"))); +} + } // namespace } // namespace clangd } // namespace clang |