[clang-tools-extra] [clangd] [Modules] Add VFS to ASTUnit::LoadFromASTFile (PR #113879)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 28 02:22:08 PDT 2024
================
@@ -127,33 +127,39 @@ struct ModuleFile {
std::string ModuleFilePath;
};
-bool IsModuleFileUpToDate(PathRef ModuleFilePath,
- const PrerequisiteModules &RequisiteModules,
- llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
+bool IsModuleFileUpToDate(
+ PathRef ModuleFilePath,
+ const PrerequisiteModules &RequisiteModules,
+ const CompilerInvocation &CI,
+ llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
+ CompilerInstance Clang;
+ Clang.setInvocation(std::make_shared<CompilerInvocation>(CI));
+
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
CompilerInstance::createDiagnostics(new DiagnosticOptions());
+ Clang.setDiagnostics(Diags.get());
+
+ HeaderSearchOptions &HSOpts = Clang.getHeaderSearchOpts();
+ RequisiteModules.adjustHeaderSearchOptions(HSOpts);
+ HSOpts.ForceCheckCXX20ModulesInputFiles = true;
+ HSOpts.ValidateASTInputFilesContent = true;
- auto HSOpts = std::make_shared<HeaderSearchOptions>();
- RequisiteModules.adjustHeaderSearchOptions(*HSOpts);
- HSOpts->ForceCheckCXX20ModulesInputFiles = true;
- HSOpts->ValidateASTInputFilesContent = true;
-
- PCHContainerOperations PCHOperations;
- std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
- ModuleFilePath.str(), PCHOperations.getRawReader(), ASTUnit::LoadASTOnly,
- Diags, FileSystemOptions(), std::move(HSOpts),
- /*LangOpts=*/nullptr, /*OnlyLocalDecls=*/false,
- /*CaptureDiagnostics=*/CaptureDiagsKind::None,
- /*AllowASTWithCompilerErrors=*/false, /*UserFilesAreVolatile=*/false,
- VFS);
-
- if (!Unit)
+ Clang.getLangOpts().SkipODRCheckInGMF = true;
+ Clang.createPreprocessor(TU_Complete);
+
+ FileManager *FM = Clang.createFileManager(VFS);
+ Clang.createSourceManager(*FM);
+ if (!Clang.createTarget())
return false;
- auto Reader = Unit->getASTReader();
+ auto Reader = Clang.getASTReader();
----------------
kadircet wrote:
i think we should call `Clang.createASTReader()` first. I don't see any of the previous call creating that.
https://github.com/llvm/llvm-project/pull/113879
More information about the cfe-commits
mailing list