@@ -916,6 +916,18 @@ using CompilerArgInstanceCacheMap =
916
916
llvm::StringMap<std::pair<std::unique_ptr<CompilerInstance>,
917
917
std::unique_ptr<ModuleDependenciesCache>>>;
918
918
919
+ static void
920
+ updateCachedInstanceSearchPaths (CompilerInstance &cachedInstance,
921
+ const CompilerInstance &invocationInstance) {
922
+ cachedInstance.getASTContext ().SearchPathOpts =
923
+ invocationInstance.getASTContext ().SearchPathOpts ;
924
+ // The Clang Importer arguments must also match those of the current
925
+ // invocation instead of the cached one because they include search
926
+ // path directives for Clang.
927
+ cachedInstance.getASTContext ().ClangImporterOpts =
928
+ invocationInstance.getASTContext ().ClangImporterOpts ;
929
+ }
930
+
919
931
static bool
920
932
forEachBatchEntry (CompilerInstance &invocationInstance,
921
933
ModuleDependenciesCache &invocationCache,
@@ -950,13 +962,9 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
950
962
// before.
951
963
pInstance = (*subInstanceMap)[entry.arguments ].first .get ();
952
964
pCache = (*subInstanceMap)[entry.arguments ].second .get ();
953
- // We must update the search paths of this instance to instead reflect those of the current
954
- // invocation's.
955
- for (auto &path : invocationInstance.getASTContext ().SearchPathOpts .ImportSearchPaths )
956
- pInstance->getASTContext ().addSearchPath (path, false , false );
957
- for (auto &path : invocationInstance.getASTContext ().SearchPathOpts .FrameworkSearchPaths )
958
- pInstance->getASTContext ().addSearchPath (path.Path , true , path.IsSystem );
959
-
965
+ // We must update the search paths of this instance to instead reflect
966
+ // those of the current scanner invocation.
967
+ updateCachedInstanceSearchPaths (*pInstance, invocationInstance);
960
968
} else {
961
969
// Create a new instance by the arguments and save it in the map.
962
970
subInstanceMap->insert (
0 commit comments