[clang] [clang][deps] Make dependency directives getter thread-safe (PR #136178)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 18 13:36:07 PDT 2025


================
@@ -92,16 +92,10 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir,
   }
 
   Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile);
-  if (getPreprocessorOpts().DependencyDirectivesForFile &&
-      FID != PredefinesFileID) {
-    if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID)) {
-      if (std::optional<ArrayRef<dependency_directives_scan::Directive>>
-              DepDirectives =
-                  getPreprocessorOpts().DependencyDirectivesForFile(*File)) {
-        TheLexer->DepDirectives = *DepDirectives;
-      }
-    }
-  }
+  if (GetDependencyDirectives && FID != PredefinesFileID)
+    if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID))
+      if (auto MaybeDepDirectives = GetDependencyDirectives(FileMgr, *File))
----------------
cyndyishida wrote:

Apologies if this is obvious, but what is the difference between the `FileMgr`  in the `Preprocessor` compared to the `FileMgr` that's tied to the CompilerInstance object created in https://github.com/llvm/llvm-project/pull/136178/files#diff-9190b5361d3722e679a0ea59ff46cc21f6d10d6e61049d73b3bc2e1ea56eb8f6R1243 ? 

IOW, why is the potential assignment of DepDirectivesGetter's attributes on each call to the function & not during assignment of the function object?

https://github.com/llvm/llvm-project/pull/136178


More information about the cfe-commits mailing list