@@ -966,10 +966,8 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
966966 // FIXME: The following attempts to do an initial ReadAST invocation to verify
967967 // the PCH, without causing trouble for the existing CompilerInstance.
968968 // Look into combining creating the ASTReader along with verification + update
969- // if necessary, so that we can create and use one ASTReader in the common case
970- // when there is no need for update.
971- clang::CompilerInstance CI (Impl.Instance ->getPCHContainerOperations (),
972- &Impl.Instance ->getModuleCache ());
969+ // if necessary, so that we can create and use one ASTReader in the common
970+ // case when there is no need for update.
973971 auto invocation =
974972 std::make_shared<clang::CompilerInvocation>(*Impl.Invocation );
975973 invocation->getPreprocessorOpts ().DisablePCHOrModuleValidation =
@@ -985,7 +983,9 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
985983 invocation->getPreprocessorOpts ().RemappedFileBuffers .clear ();
986984
987985 clang::DiagnosticOptions diagOpts;
988- CI.setInvocation (std::move (invocation));
986+ clang::CompilerInstance CI (std::move (invocation),
987+ Impl.Instance ->getPCHContainerOperations (),
988+ &Impl.Instance ->getModuleCache ());
989989 CI.setTarget (&Impl.Instance ->getTarget ());
990990 CI.setDiagnostics (&*clang::CompilerInstance::createDiagnostics (
991991 Impl.Instance ->getVirtualFileSystem (), diagOpts));
@@ -1363,12 +1363,10 @@ ClangImporter::create(ASTContext &ctx,
13631363 std::make_unique<clang::ObjectFilePCHContainerWriter>());
13641364 PCHContainerOperations->registerReader (
13651365 std::make_unique<clang::ObjectFilePCHContainerReader>());
1366- importer->Impl .Instance .reset (
1367- new clang::CompilerInstance ( std::move (PCHContainerOperations)));
1366+ importer->Impl .Instance .reset (new clang::CompilerInstance (
1367+ importer-> Impl . Invocation , std::move (PCHContainerOperations)));
13681368 }
13691369 auto &instance = *importer->Impl .Instance ;
1370- instance.setInvocation (importer->Impl .Invocation );
1371-
13721370 if (tracker)
13731371 instance.addDependencyCollector (tracker->getClangCollector ());
13741372
@@ -1898,9 +1896,8 @@ std::string ClangImporter::getBridgingHeaderContents(
18981896 clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
18991897
19001898 clang::CompilerInstance rewriteInstance (
1901- Impl.Instance ->getPCHContainerOperations (),
1902- &Impl.Instance ->getModuleCache ());
1903- rewriteInstance.setInvocation (invocation);
1899+ std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
1900+ &Impl.Instance ->getModuleCache ());
19041901 rewriteInstance.createDiagnostics (fileManager.getVirtualFileSystem (),
19051902 new clang::IgnoringDiagConsumer);
19061903 rewriteInstance.setFileManager (&fileManager);
@@ -2004,9 +2001,8 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20042001 clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
20052002
20062003 auto clonedInstance = std::make_unique<clang::CompilerInstance>(
2007- Impl.Instance ->getPCHContainerOperations (),
2008- &Impl.Instance ->getModuleCache ());
2009- clonedInstance->setInvocation (std::move (invocation));
2004+ std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
2005+ &Impl.Instance ->getModuleCache ());
20102006 clonedInstance->createDiagnostics (fileManager.getVirtualFileSystem (),
20112007 &Impl.Instance ->getDiagnosticClient (),
20122008 /* ShouldOwnClient=*/ false );
0 commit comments