aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2022-10-04 15:08:08 -0700
committerBen Langmuir <blangmuir@apple.com>2022-10-05 13:12:43 -0700
commit5ea78c4113f8d2c8be24152f2dd0cadaea352c9d (patch)
treec0561866efb1c7cbe9b5b5e26ae615ef956c181d /clang/lib/Frontend/CompilerInstance.cpp
parent1888dc91ac872146d106de9f8ea73b9148c920ff (diff)
downloadllvm-5ea78c4113f8d2c8be24152f2dd0cadaea352c9d.zip
llvm-5ea78c4113f8d2c8be24152f2dd0cadaea352c9d.tar.gz
llvm-5ea78c4113f8d2c8be24152f2dd0cadaea352c9d.tar.bz2
[clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef
Update SourceManager::ContentCache::OrigEntry to keep the original FileEntryRef, and use that to enable ModuleMap::getModuleMapFile* to return the original FileEntryRef. This change should be NFC for most users of SourceManager::ContentCache, but it could affect behaviour for users of getNameAsRequested such as in compileModuleImpl. I have not found a way to detect that difference without additional functional changes, other than incidental cases like changes from / to \ on Windows so there is no new test. Differential Revision: https://reviews.llvm.org/D135220
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 995c94b..46f97e0 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -423,7 +423,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags,
// Remap files in the source manager (with other files).
for (const auto &RF : InitOpts.RemappedFiles) {
// Find the file that we're mapping to.
- auto ToFile = FileMgr.getFile(RF.second);
+ Optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second;
continue;
@@ -431,7 +431,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags,
// Create the file entry for the file that we're mapping from.
const FileEntry *FromFile =
- FileMgr.getVirtualFile(RF.first, (*ToFile)->getSize(), 0);
+ FileMgr.getVirtualFile(RF.first, ToFile->getSize(), 0);
if (!FromFile) {
Diags.Report(diag::err_fe_remap_missing_from_file) << RF.first;
continue;
@@ -1278,19 +1278,17 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
Instance.getFrontendOpts().AllowPCMWithCompilerErrors;
}
-static const FileEntry *getPublicModuleMap(const FileEntry *File,
- FileManager &FileMgr) {
- StringRef Filename = llvm::sys::path::filename(File->getName());
- SmallString<128> PublicFilename(File->getDir()->getName());
+static Optional<FileEntryRef> getPublicModuleMap(FileEntryRef File,
+ FileManager &FileMgr) {
+ StringRef Filename = llvm::sys::path::filename(File.getName());
+ SmallString<128> PublicFilename(File.getDir().getName());
if (Filename == "module_private.map")
llvm::sys::path::append(PublicFilename, "module.map");
else if (Filename == "module.private.modulemap")
llvm::sys::path::append(PublicFilename, "module.modulemap");
else
- return nullptr;
- if (auto FE = FileMgr.getFile(PublicFilename))
- return *FE;
- return nullptr;
+ return None;
+ return FileMgr.getOptionalFileRef(PublicFilename);
}
/// Compile a module file for the given module in a separate compiler instance,
@@ -1306,19 +1304,16 @@ static bool compileModule(CompilerInstance &ImportingInstance,
ModuleMap &ModMap
= ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
bool Result;
- if (const FileEntry *ModuleMapFile =
+ if (Optional<FileEntryRef> ModuleMapFile =
ModMap.getContainingModuleMapFile(Module)) {
// Canonicalize compilation to start with the public module map. This is
// vital for submodules declarations in the private module maps to be
// correctly parsed when depending on a top level module in the public one.
- if (const FileEntry *PublicMMFile = getPublicModuleMap(
- ModuleMapFile, ImportingInstance.getFileManager()))
+ if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap(
+ *ModuleMapFile, ImportingInstance.getFileManager()))
ModuleMapFile = PublicMMFile;
- // FIXME: Update header search to keep FileEntryRef rather than rely on
- // getLastRef().
- StringRef ModuleMapFilePath =
- ModuleMapFile->getLastRef().getNameAsRequested();
+ StringRef ModuleMapFilePath = ModuleMapFile->getNameAsRequested();
// Use the module map where this module resides.
Result = compileModuleImpl(
@@ -1346,7 +1341,7 @@ static bool compileModule(CompilerInstance &ImportingInstance,
[&](CompilerInstance &Instance) {
std::unique_ptr<llvm::MemoryBuffer> ModuleMapBuffer =
llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent);
- ModuleMapFile = Instance.getFileManager().getVirtualFile(
+ const FileEntry *ModuleMapFile = Instance.getFileManager().getVirtualFile(
FakeModuleMapFile, InferredModuleMapContent.size(), 0);
Instance.getSourceManager().overrideFileContents(
ModuleMapFile, std::move(ModuleMapBuffer));