Author: Aleksandr Platonov Date: 2020-11-09T21:40:45+03:00 New Revision: 1bbf87e22a73011fdea411baf8fe768f854d497c
URL: https://github.com/llvm/llvm-project/commit/1bbf87e22a73011fdea411baf8fe768f854d497c DIFF: https://github.com/llvm/llvm-project/commit/1bbf87e22a73011fdea411baf8fe768f854d497c.diff LOG: [clangd][remote] Check an index file correctly There is not reason to check `std::make_unique<...>(..)` return value, but `clangd::clang::loadIndex()` returns `nullptr` if an index file could not be loaded (e.g. incorrect version). Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D91049 Added: Modified: clang-tools-extra/clangd/index/remote/server/Server.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp index 4a479eece50f..fac1bd98ad5f 100644 --- a/clang-tools-extra/clangd/index/remote/server/Server.cpp +++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp @@ -357,24 +357,23 @@ int main(int argc, char *argv[]) { return Status.getError().value(); } - auto Index = std::make_unique<clang::clangd::SwapIndex>( - clang::clangd::loadIndex(IndexPath)); - - if (!Index) { + auto SymIndex = clang::clangd::loadIndex(IndexPath); + if (!SymIndex) { llvm::errs() << "Failed to open the index.\n"; return -1; } + clang::clangd::SwapIndex Index(std::move(SymIndex)); std::thread HotReloadThread([&Index, &Status, &FS]() { llvm::vfs::Status LastStatus = *Status; static constexpr auto RefreshFrequency = std::chrono::seconds(30); while (!clang::clangd::shutdownRequested()) { - hotReload(*Index, llvm::StringRef(IndexPath), LastStatus, FS); + hotReload(Index, llvm::StringRef(IndexPath), LastStatus, FS); std::this_thread::sleep_for(RefreshFrequency); } }); - runServerAndWait(*Index, ServerAddress, IndexPath); + runServerAndWait(Index, ServerAddress, IndexPath); HotReloadThread.join(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits