Index: clang/include/clang/Frontend/ASTUnit.h =================================================================== --- clang/include/clang/Frontend/ASTUnit.h +++ clang/include/clang/Frontend/ASTUnit.h @@ -876,7 +876,6 @@ CodeCompleteConsumer &Consumer, std::shared_ptr PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, - SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl &StoredDiagnostics, SmallVectorImpl &OwnedBuffers); Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -2132,8 +2132,8 @@ bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr PCHContainerOps, - DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, - FileManager &FileMgr, SmallVectorImpl &StoredDiagnostics, + DiagnosticsEngine &Diag, LangOptions &LangOpts, + SmallVectorImpl &StoredDiagnostics, SmallVectorImpl &OwnedBuffers) { if (!Invocation) return; @@ -2211,9 +2211,12 @@ Language::LLVM_IR && "IR inputs not support here!"); - // Use the source and file managers that we were given. - Clang->setFileManager(&FileMgr); - Clang->setSourceManager(&SourceMgr); + // Initialize file and source managers up front so that the caller can access + // them after. + Clang->createFileManager(FS); + FileMgr = &Clang->getFileManager(); + Clang->createSourceManager(*FileMgr); + SourceMgr = &Clang->getSourceManager(); // Remap files. PreprocessorOpts.clearRemappedFiles(); Index: clang/tools/libclang/CIndexCodeCompletion.cpp =================================================================== --- clang/tools/libclang/CIndexCodeCompletion.cpp +++ clang/tools/libclang/CIndexCodeCompletion.cpp @@ -359,8 +359,6 @@ : CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions), Diag(new DiagnosticsEngine( IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts)), - FileMgr(std::move(FileMgr)), - SourceMgr(new SourceManager(*Diag, *this->FileMgr)), CodeCompletionAllocator( std::make_shared()), Contexts(CXCompletionContext_Unknown), @@ -755,14 +753,15 @@ LibclangInvocationReporter InvocationReporter( *CXXIdx, LibclangInvocationReporter::OperationKind::CompletionOperation, TU->ParsingOptions, CArgs, CompletionInvocation, unsaved_files); - AST->CodeComplete(complete_filename, complete_line, complete_column, - RemappedFiles, (options & CXCodeComplete_IncludeMacros), - (options & CXCodeComplete_IncludeCodePatterns), - IncludeBriefComments, Capture, - CXXIdx->getPCHContainerOperations(), *Results->Diag, - Results->LangOpts, *Results->SourceMgr, *Results->FileMgr, - Results->Diagnostics, Results->TemporaryBuffers); - + AST->CodeComplete( + complete_filename, complete_line, complete_column, RemappedFiles, + (options & CXCodeComplete_IncludeMacros), + (options & CXCodeComplete_IncludeCodePatterns), IncludeBriefComments, + Capture, CXXIdx->getPCHContainerOperations(), *Results->Diag, + Results->LangOpts, Results->Diagnostics, Results->TemporaryBuffers); + + Results->FileMgr = &AST->getFileManager(); + Results->SourceMgr = &AST->getSourceManager(); Results->DiagnosticsWrappers.resize(Results->Diagnostics.size()); // Keep a reference to the allocator used for cached global completions, so