Author: kadircet Date: Mon Apr 15 07:38:46 2019 New Revision: 358413 URL: http://llvm.org/viewvc/llvm-project?rev=358413&view=rev Log: [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 Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=358413&r1=358412&r2=358413&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original) +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Apr 15 07:38:46 2019 @@ -285,6 +285,11 @@ bool SymbolCollector::handleDeclOccurenc 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::addDeclar 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 = Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=358413&r1=358412&r2=358413&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Mon Apr 15 07:38:46 2019 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits