Repository: llvm/llvm-project
File: clang/include/clang/Serialization/ASTReader.h (C/C++)

Code before:

  /// Read the unhashed control block.
  ///
  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
  /// \c F.Data and reading ahead.
  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
                                         unsigned ClientLoadCapabilities);

  static ASTReadResult readUnhashedControlBlockImpl(
      ModuleFile *F, llvm::StringRef StreamData, StringRef Filename,
      unsigned ClientLoadCapabilities,
      bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
      bool ValidateDiagnosticOptions);

  llvm::Error ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
  llvm::Error ReadExtensionBlock(ModuleFile &F);
  void ReadModuleOffsetMap(ModuleFile &F) const;
  void ParseLineTable(ModuleFile &F, const RecordData &Record);
  llvm::Error ReadSourceManagerBlock(ModuleFile &F);
  SourceLocation getImportLocation(ModuleFile *F);

  /// If a relocation check happened, the optional holds a pointer to the
  /// discovered Module. The second element determines whether to emit related
  /// validation errors.
  using RelocationCheckResult = std::pair<std::optional<Module *>, bool>;
  RelocationCheckResult checkIfModuleRelocated(ModuleFile &F,
                                               bool DirectoryCheck = false);
  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
                                       const ModuleFile *ImportedBy,
                                       unsigned ClientLoadCapabilities);
  llvm::Error ReadSubmoduleBlock(ModuleFile &F,
                                 unsigned ClientLoadCapabilities);
  static bool ParseLanguageOptions(const RecordData &Record,
                                   StringRef ModuleFilename, bool Complain,
                                   ASTReaderListener &Listener,
                                   bool AllowCompatibleDifferences);
  static bool ParseCodeGenOptions(const RecordData &Record,
                                  StringRef ModuleFilename, bool Complain,
                                  ASTReaderListener &Listener,
                                  bool AllowCompatibleDifferences);
  static bool ParseTargetOptions(const RecordData &Record,
                                 StringRef ModuleFilename, bool Complain,
                                 ASTReaderListener &Listener,
                                 bool AllowCompatibleDifferences);
  static bool ParseDiagnosticOptions(const RecordData &Record,
                                     StringRef ModuleFilename, bool Complain,
                                     ASTReaderListener &Listener);
  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
                                     ASTReaderListener &Listener);
  static bool ParseHeaderSearchOptions(const RecordData &Record,
                                       StringRef ModuleFilename, bool Complain,

Review comment (bug):
This doesn't actually check if a module has been relocated, right? Maybe we should call this something like `getModuleForRelocationChecks()`? It might also be worth explaining the difference between `std::nullopt` and `std::optional(nullptr)` of the first member in the result.

Code after:

  /// Read the unhashed control block.
  ///
  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
  /// \c F.Data and reading ahead.
  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
                                         unsigned ClientLoadCapabilities);

  static ASTReadResult readUnhashedControlBlockImpl(
      ModuleFile *F, llvm::StringRef StreamData, StringRef Filename,
      unsigned ClientLoadCapabilities,
      bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
      bool ValidateDiagnosticOptions);

  llvm::Error ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
  llvm::Error ReadExtensionBlock(ModuleFile &F);
  void ReadModuleOffsetMap(ModuleFile &F) const;
  void ParseLineTable(ModuleFile &F, const RecordData &Record);
  llvm::Error ReadSourceManagerBlock(ModuleFile &F);
  SourceLocation getImportLocation(ModuleFile *F);

  /// The first element is `std::nullopt` if relocation check should be skipped.
  /// Otherwise, the optional holds a pointer to the discovered module.
  /// The pointer can be `nullptr` if the discovery was unsuccessful.
  /// The second element determines whether to emit related errors.
  using RelocationResult = std::pair<std::optional<Module *>, bool>;

  /// Determine whether a relocation check for a module should be performed
  /// by attempting to resolve the same module via lookup.
  /// If so, also determine whether to emit errors for the relocation.
  /// A relocated module is defined as a module that is either no longer
  /// resolvable from the modulemap or search path it originally compiled it's
  /// definition from.
  RelocationResult getModuleForRelocationChecks(ModuleFile &F,
                                                bool DirectoryCheck = false);
  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
                                       const ModuleFile *ImportedBy,
                                       unsigned ClientLoadCapabilities);
  llvm::Error ReadSubmoduleBlock(ModuleFile &F,
                                 unsigned ClientLoadCapabilities);
  static bool ParseLanguageOptions(const RecordData &Record,
                                   StringRef ModuleFilename, bool Complain,
                                   ASTReaderListener &Listener,
                                   bool AllowCompatibleDifferences);
  static bool ParseCodeGenOptions(const RecordData &Record,
                                  StringRef ModuleFilename, bool Complain,
                                  ASTReaderListener &Listener,
                                  bool AllowCompatibleDifferences);
  static bool ParseTargetOptions(const RecordData &Record,
                                 StringRef ModuleFilename, bool Complain,
                                 ASTReaderListener &Listener,