kadircet updated this revision to Diff 541938. kadircet added a comment. Fix some tsan issues
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155619/new/ https://reviews.llvm.org/D155619 Files: clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/ClangdServer.h clang-tools-extra/clangd/Preamble.cpp
Index: clang-tools-extra/clangd/Preamble.cpp =================================================================== --- clang-tools-extra/clangd/Preamble.cpp +++ clang-tools-extra/clangd/Preamble.cpp @@ -11,6 +11,8 @@ #include "Compiler.h" #include "Config.h" #include "Diagnostics.h" +#include "FS.h" +#include "FeatureModule.h" #include "Headers.h" #include "Protocol.h" #include "SourceCode.h" @@ -21,8 +23,10 @@ #include "support/ThreadsafeFS.h" #include "support/Trace.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/Type.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticLex.h" +#include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" @@ -51,12 +55,17 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ErrorOr.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <chrono> #include <cstddef> +#include <cstdint> +#include <cstdlib> #include <functional> #include <memory> #include <optional> @@ -616,7 +625,8 @@ }); llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine = CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(), - &PreambleDiagnostics, false); + &PreambleDiagnostics, + /*ShouldOwnClient=*/false); const Config &Cfg = Config::current(); PreambleDiagnostics.setLevelAdjuster([&](DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) { @@ -663,8 +673,12 @@ auto BuiltPreamble = PrecompiledPreamble::Build( CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, Stats ? TimedFS : StatCacheFS, std::make_shared<PCHContainerOperations>(), - StoreInMemory, /*StoragePath=*/StringRef(), CapturedInfo); + StoreInMemory, /*StoragePath=*/"", CapturedInfo); PreambleTimer.stopTimer(); + // Reset references to ref-counted-ptrs before executing the callbacks, to + // prevent resetting them concurrently. + PreambleDiagsEngine.reset(); + CI.DiagnosticOpts.reset(); // When building the AST for the main file, we do want the function // bodies. Index: clang-tools-extra/clangd/ClangdServer.h =================================================================== --- clang-tools-extra/clangd/ClangdServer.h +++ clang-tools-extra/clangd/ClangdServer.h @@ -185,10 +185,6 @@ /// regions in the document. bool PublishInactiveRegions = false; - /// Whether to run preamble indexing asynchronously in an independent - /// thread. - bool AsyncPreambleIndexing = false; - explicit operator TUScheduler::Options() const; }; // Sensible default options for use in tests. Index: clang-tools-extra/clangd/ClangdServer.cpp =================================================================== --- clang-tools-extra/clangd/ClangdServer.cpp +++ clang-tools-extra/clangd/ClangdServer.cpp @@ -67,11 +67,10 @@ UpdateIndexCallbacks(FileIndex *FIndex, ClangdServer::Callbacks *ServerCallbacks, const ThreadsafeFS &TFS, AsyncTaskRunner *Tasks, - bool CollectInactiveRegions, - const ClangdServer::Options &Opts) - : FIndex(FIndex), ServerCallbacks(ServerCallbacks), - TFS(TFS), Stdlib{std::make_shared<StdLibSet>()}, Tasks(Tasks), - CollectInactiveRegions(CollectInactiveRegions), Opts(Opts) {} + bool CollectInactiveRegions) + : FIndex(FIndex), ServerCallbacks(ServerCallbacks), TFS(TFS), + Stdlib{std::make_shared<StdLibSet>()}, Tasks(Tasks), + CollectInactiveRegions(CollectInactiveRegions) {} void onPreambleAST( PathRef Path, llvm::StringRef Version, CapturedASTCtx ASTCtx, @@ -94,7 +93,7 @@ ASTCtx.getPreprocessor(), *CanonIncludes); }; - if (Opts.AsyncPreambleIndexing && Tasks) { + if (Tasks) { Tasks->runAsync("Preamble indexing for:" + Path + Version, std::move(Task)); } else @@ -164,7 +163,6 @@ std::shared_ptr<StdLibSet> Stdlib; AsyncTaskRunner *Tasks; bool CollectInactiveRegions; - const ClangdServer::Options &Opts; }; class DraftStoreFS : public ThreadsafeFS { @@ -229,7 +227,7 @@ std::make_unique<UpdateIndexCallbacks>( DynamicIdx.get(), Callbacks, TFS, IndexTasks ? &*IndexTasks : nullptr, - PublishInactiveRegions, Opts)); + PublishInactiveRegions)); // Adds an index to the stack, at higher priority than existing indexes. auto AddIndex = [&](SymbolIndex *Idx) { if (this->Index != nullptr) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits