[sourcekit] Stop storing a bare reference to LangSupport in ASTManager

This fixes a use-after-free when an AST build finishes after shutdown().
This commit is contained in:
Ben Langmuir
2018-09-25 14:00:59 -07:00
parent 1015da026e
commit b3422c1e9d
6 changed files with 47 additions and 42 deletions

View File

@@ -179,7 +179,10 @@ SwiftLangSupport::SwiftLangSupport(SourceKit::Context &SKCtx)
llvm::sys::path::append(LibPath, "swift");
RuntimeResourcePath = LibPath.str();
ASTMgr = std::make_shared<SwiftASTManager>(*this);
Stats = std::make_shared<SwiftStatistics>();
EditorDocuments = std::make_shared<SwiftEditorDocumentFileMap>();
ASTMgr = std::make_shared<SwiftASTManager>(EditorDocuments, Stats,
RuntimeResourcePath);
// By default, just use the in-memory cache.
CCCache->inMemory = llvm::make_unique<ide::CodeCompletionCache>();
}
@@ -766,7 +769,7 @@ std::string SwiftLangSupport::resolvePathSymlinks(StringRef FilePath) {
void SwiftLangSupport::getStatistics(StatisticsReceiver receiver) {
std::vector<Statistic *> stats = {
#define SWIFT_STATISTIC(VAR, UID, DESC) &Stats.VAR,
#define SWIFT_STATISTIC(VAR, UID, DESC) &Stats->VAR,
#include "SwiftStatistics.def"
};
receiver(stats);