================
@@ -127,50 +128,64 @@ struct ModuleFile {
   std::string ModuleFilePath;
 };
 
-bool IsModuleFileUpToDate(
-    PathRef ModuleFilePath,
-    const PrerequisiteModules &RequisiteModules) {
-IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
-      CompilerInstance::createDiagnostics(new DiagnosticOptions());
-
+bool IsModuleFileUpToDate(PathRef ModuleFilePath,
+                          const PrerequisiteModules &RequisiteModules,
+                          llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) 
{
   auto HSOpts = std::make_shared<HeaderSearchOptions>();
   RequisiteModules.adjustHeaderSearchOptions(*HSOpts);
   HSOpts->ForceCheckCXX20ModulesInputFiles = true;
   HSOpts->ValidateASTInputFilesContent = true;
 
+  IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
+      CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+  LangOptions LangOpts;
+  LangOpts.SkipODRCheckInGMF = true;
+
+  FileManager FileMgr(FileSystemOptions(), VFS);
+
+  SourceManager SourceMgr(*Diags, FileMgr);
+
+  HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
+                          /*Target=*/nullptr);
+
+  TrivialModuleLoader ModuleLoader;
+  Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
+                  SourceMgr, HeaderInfo, ModuleLoader);
+
+  IntrusiveRefCntPtr<InMemoryModuleCache> ModuleCache = new 
InMemoryModuleCache;
----------------
ChuanqiXu9 wrote:

This was the defect on the clang side. The module manager will store the 
`ModuleCache` as `IntrusiveRefCntPtr`: 
https://github.com/llvm/llvm-project/blob/0c1c37bfbed08c9d4e414a10f46cbed9a3e4c870/clang/include/clang/Serialization/ModuleManager.h#L67-L68
 while it was not required by the constructor.

And if I make the `ModuleCache` as a local variable, then it crashes with 
invalid pointer.

https://github.com/llvm/llvm-project/pull/113879
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to