[clang] Make deprecations of some FileManager APIs formal (#110014)
Some `FileManager` APIs still return `{File,Directory}Entry` instead of
the preferred `{File,Directory}EntryRef`. These are documented to be
deprecated, but don't have the attribute that warns on their usage. This
PR marks them as such with `LLVM_DEPRECATED()` and replaces their usage
with the recommended counterparts. NFCI.
This commit is contained in:
@@ -199,7 +199,7 @@ int main(int argc, const char **argv) {
|
||||
for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
|
||||
OS << " {\n";
|
||||
OS << " \"FilePath\": \"" << *I << "\",\n";
|
||||
const auto Entry = FileMgr.getFile(*I);
|
||||
const auto Entry = FileMgr.getOptionalFileRef(*I);
|
||||
auto ID = SM.translateFile(*Entry);
|
||||
std::string Content;
|
||||
llvm::raw_string_ostream ContentStream(Content);
|
||||
|
||||
@@ -814,8 +814,8 @@ llvm::SmallVector<llvm::StringRef> ancestorNamespaces(llvm::StringRef NS) {
|
||||
|
||||
// Checks whether \p FileName is a valid spelling of main file.
|
||||
bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
|
||||
auto FE = SM.getFileManager().getFile(FileName);
|
||||
return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
|
||||
auto FE = SM.getFileManager().getOptionalFileRef(FileName);
|
||||
return FE && FE == SM.getFileEntryRefForID(SM.getMainFileID());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -397,10 +397,10 @@ TEST(ParsedASTTest, PatchesAdditionalIncludes) {
|
||||
auto &FM = SM.getFileManager();
|
||||
// Copy so that we can use operator[] to get the children.
|
||||
IncludeStructure Includes = PatchedAST->getIncludeStructure();
|
||||
auto MainFE = FM.getFile(testPath("foo.cpp"));
|
||||
auto MainFE = FM.getOptionalFileRef(testPath("foo.cpp"));
|
||||
ASSERT_TRUE(MainFE);
|
||||
auto MainID = Includes.getID(*MainFE);
|
||||
auto AuxFE = FM.getFile(testPath("sub/aux.h"));
|
||||
auto AuxFE = FM.getOptionalFileRef(testPath("sub/aux.h"));
|
||||
ASSERT_TRUE(AuxFE);
|
||||
auto AuxID = Includes.getID(*AuxFE);
|
||||
EXPECT_THAT(Includes.IncludeChildren[*MainID], Contains(*AuxID));
|
||||
|
||||
@@ -60,7 +60,7 @@ protected:
|
||||
llvm::SmallVector<Hinted<Header>> findHeaders(llvm::StringRef FileName) {
|
||||
return include_cleaner::findHeaders(
|
||||
AST->sourceManager().translateFileLineCol(
|
||||
AST->fileManager().getFile(FileName).get(),
|
||||
*AST->fileManager().getOptionalFileRef(FileName),
|
||||
/*Line=*/1, /*Col=*/1),
|
||||
AST->sourceManager(), &PI);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ TEST_F(RecordPPTest, CapturesMacroRefs) {
|
||||
const auto &SM = AST.sourceManager();
|
||||
|
||||
SourceLocation Def = SM.getComposedLoc(
|
||||
SM.translateFile(AST.fileManager().getFile("header.h").get()),
|
||||
SM.translateFile(*AST.fileManager().getOptionalFileRef("header.h")),
|
||||
Header.point("def"));
|
||||
ASSERT_THAT(Recorded.MacroReferences, Not(IsEmpty()));
|
||||
Symbol OrigX = Recorded.MacroReferences.front().Target;
|
||||
@@ -368,29 +368,29 @@ TEST_F(PragmaIncludeTest, IWYUKeep) {
|
||||
TestAST Processed = build();
|
||||
auto &FM = Processed.fileManager();
|
||||
|
||||
EXPECT_FALSE(PI.shouldKeep(FM.getFile("normal.h").get()));
|
||||
EXPECT_FALSE(PI.shouldKeep(FM.getFile("std/vector").get()));
|
||||
EXPECT_FALSE(PI.shouldKeep(*FM.getOptionalFileRef("normal.h")));
|
||||
EXPECT_FALSE(PI.shouldKeep(*FM.getOptionalFileRef("std/vector")));
|
||||
|
||||
// Keep
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep1.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep2.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep3.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep4.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep5.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("keep6.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("std/map").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep1.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep2.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep3.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep4.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep5.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("keep6.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("std/map")));
|
||||
|
||||
// Exports
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("export1.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("export2.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("export3.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("std/set").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("export1.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("export2.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("export3.h")));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("std/set")));
|
||||
}
|
||||
|
||||
TEST_F(PragmaIncludeTest, AssociatedHeader) {
|
||||
createEmptyFiles({"foo/main.h", "bar/main.h", "bar/other.h", "std/vector"});
|
||||
auto IsKeep = [&](llvm::StringRef Name, TestAST &AST) {
|
||||
return PI.shouldKeep(AST.fileManager().getFile(Name).get());
|
||||
return PI.shouldKeep(*AST.fileManager().getOptionalFileRef(Name));
|
||||
};
|
||||
|
||||
Inputs.FileName = "main.cc";
|
||||
@@ -452,19 +452,19 @@ TEST_F(PragmaIncludeTest, IWYUPrivate) {
|
||||
// IWYU pragma: private
|
||||
)cpp";
|
||||
TestAST Processed = build();
|
||||
auto PrivateFE = Processed.fileManager().getFile("private.h");
|
||||
auto PrivateFE = Processed.fileManager().getOptionalFileRef("private.h");
|
||||
assert(PrivateFE);
|
||||
EXPECT_TRUE(PI.isPrivate(PrivateFE.get()));
|
||||
EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public2.h\"");
|
||||
EXPECT_TRUE(PI.isPrivate(*PrivateFE));
|
||||
EXPECT_EQ(PI.getPublic(*PrivateFE), "\"public2.h\"");
|
||||
|
||||
auto PublicFE = Processed.fileManager().getFile("public.h");
|
||||
auto PublicFE = Processed.fileManager().getOptionalFileRef("public.h");
|
||||
assert(PublicFE);
|
||||
EXPECT_EQ(PI.getPublic(PublicFE.get()), ""); // no mapping.
|
||||
EXPECT_FALSE(PI.isPrivate(PublicFE.get()));
|
||||
EXPECT_EQ(PI.getPublic(*PublicFE), ""); // no mapping.
|
||||
EXPECT_FALSE(PI.isPrivate(*PublicFE));
|
||||
|
||||
auto Private2FE = Processed.fileManager().getFile("private2.h");
|
||||
auto Private2FE = Processed.fileManager().getOptionalFileRef("private2.h");
|
||||
assert(Private2FE);
|
||||
EXPECT_TRUE(PI.isPrivate(Private2FE.get()));
|
||||
EXPECT_TRUE(PI.isPrivate(*Private2FE));
|
||||
}
|
||||
|
||||
TEST_F(PragmaIncludeTest, IWYUExport) {
|
||||
@@ -486,13 +486,13 @@ TEST_F(PragmaIncludeTest, IWYUExport) {
|
||||
const auto &SM = Processed.sourceManager();
|
||||
auto &FM = Processed.fileManager();
|
||||
|
||||
EXPECT_THAT(PI.getExporters(FM.getFile("private.h").get(), FM),
|
||||
EXPECT_THAT(PI.getExporters(*FM.getOptionalFileRef("private.h"), FM),
|
||||
testing::UnorderedElementsAre(FileNamed("export1.h"),
|
||||
FileNamed("export3.h")));
|
||||
|
||||
EXPECT_TRUE(PI.getExporters(FM.getFile("export1.h").get(), FM).empty());
|
||||
EXPECT_TRUE(PI.getExporters(FM.getFile("export2.h").get(), FM).empty());
|
||||
EXPECT_TRUE(PI.getExporters(FM.getFile("export3.h").get(), FM).empty());
|
||||
EXPECT_TRUE(PI.getExporters(*FM.getOptionalFileRef("export1.h"), FM).empty());
|
||||
EXPECT_TRUE(PI.getExporters(*FM.getOptionalFileRef("export2.h"), FM).empty());
|
||||
EXPECT_TRUE(PI.getExporters(*FM.getOptionalFileRef("export3.h"), FM).empty());
|
||||
EXPECT_TRUE(
|
||||
PI.getExporters(SM.getFileEntryForID(SM.getMainFileID()), FM).empty());
|
||||
}
|
||||
@@ -548,23 +548,23 @@ TEST_F(PragmaIncludeTest, IWYUExportBlock) {
|
||||
}
|
||||
return Result;
|
||||
};
|
||||
auto Exporters = PI.getExporters(FM.getFile("private1.h").get(), FM);
|
||||
auto Exporters = PI.getExporters(*FM.getOptionalFileRef("private1.h"), FM);
|
||||
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h"),
|
||||
FileNamed("normal.h")))
|
||||
<< GetNames(Exporters);
|
||||
|
||||
Exporters = PI.getExporters(FM.getFile("private2.h").get(), FM);
|
||||
Exporters = PI.getExporters(*FM.getOptionalFileRef("private2.h"), FM);
|
||||
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h")))
|
||||
<< GetNames(Exporters);
|
||||
|
||||
Exporters = PI.getExporters(FM.getFile("private3.h").get(), FM);
|
||||
Exporters = PI.getExporters(*FM.getOptionalFileRef("private3.h"), FM);
|
||||
EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h")))
|
||||
<< GetNames(Exporters);
|
||||
|
||||
Exporters = PI.getExporters(FM.getFile("foo.h").get(), FM);
|
||||
Exporters = PI.getExporters(*FM.getOptionalFileRef("foo.h"), FM);
|
||||
EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters);
|
||||
|
||||
Exporters = PI.getExporters(FM.getFile("bar.h").get(), FM);
|
||||
Exporters = PI.getExporters(*FM.getOptionalFileRef("bar.h"), FM);
|
||||
EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters);
|
||||
}
|
||||
|
||||
@@ -580,8 +580,8 @@ TEST_F(PragmaIncludeTest, SelfContained) {
|
||||
Inputs.ExtraFiles["unguarded.h"] = "";
|
||||
TestAST Processed = build();
|
||||
auto &FM = Processed.fileManager();
|
||||
EXPECT_TRUE(PI.isSelfContained(FM.getFile("guarded.h").get()));
|
||||
EXPECT_FALSE(PI.isSelfContained(FM.getFile("unguarded.h").get()));
|
||||
EXPECT_TRUE(PI.isSelfContained(*FM.getOptionalFileRef("guarded.h")));
|
||||
EXPECT_FALSE(PI.isSelfContained(*FM.getOptionalFileRef("unguarded.h")));
|
||||
}
|
||||
|
||||
TEST_F(PragmaIncludeTest, AlwaysKeep) {
|
||||
@@ -596,8 +596,8 @@ TEST_F(PragmaIncludeTest, AlwaysKeep) {
|
||||
Inputs.ExtraFiles["usual.h"] = "#pragma once";
|
||||
TestAST Processed = build();
|
||||
auto &FM = Processed.fileManager();
|
||||
EXPECT_TRUE(PI.shouldKeep(FM.getFile("always_keep.h").get()));
|
||||
EXPECT_FALSE(PI.shouldKeep(FM.getFile("usual.h").get()));
|
||||
EXPECT_TRUE(PI.shouldKeep(*FM.getOptionalFileRef("always_keep.h")));
|
||||
EXPECT_FALSE(PI.shouldKeep(*FM.getOptionalFileRef("usual.h")));
|
||||
}
|
||||
|
||||
TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
|
||||
@@ -653,13 +653,13 @@ TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {
|
||||
// Now this build gives us a new File&Source Manager.
|
||||
TestAST Processed = build(/*ResetPragmaIncludes=*/false);
|
||||
auto &FM = Processed.fileManager();
|
||||
auto PrivateFE = FM.getFile("private.h");
|
||||
auto PrivateFE = FM.getOptionalFileRef("private.h");
|
||||
assert(PrivateFE);
|
||||
EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public.h\"");
|
||||
EXPECT_EQ(PI.getPublic(*PrivateFE), "\"public.h\"");
|
||||
|
||||
auto Private2FE = FM.getFile("private2.h");
|
||||
auto Private2FE = FM.getOptionalFileRef("private2.h");
|
||||
assert(Private2FE);
|
||||
EXPECT_THAT(PI.getExporters(Private2FE.get(), FM),
|
||||
EXPECT_THAT(PI.getExporters(*Private2FE, FM),
|
||||
testing::ElementsAre(llvm::cantFail(FM.getFileRef("public.h"))));
|
||||
}
|
||||
|
||||
@@ -676,8 +676,8 @@ TEST_F(PragmaIncludeTest, CanRecordManyTimes) {
|
||||
|
||||
TestAST Processed = build();
|
||||
auto &FM = Processed.fileManager();
|
||||
auto PrivateFE = FM.getFile("private.h");
|
||||
llvm::StringRef Public = PI.getPublic(PrivateFE.get());
|
||||
auto PrivateFE = FM.getOptionalFileRef("private.h");
|
||||
llvm::StringRef Public = PI.getPublic(*PrivateFE);
|
||||
EXPECT_EQ(Public, "\"public.h\"");
|
||||
|
||||
// This build populates same PI during build, but this time we don't have
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
I != E; ++I) {
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buf =
|
||||
llvm::MemoryBuffer::getMemBuffer(I->Code);
|
||||
const FileEntry *Entry = SM.getFileManager().getVirtualFile(
|
||||
FileEntryRef Entry = SM.getFileManager().getVirtualFileRef(
|
||||
I->FileName, Buf->getBufferSize(), /*ModificationTime=*/0);
|
||||
SM.overrideFileContents(Entry, std::move(Buf));
|
||||
}
|
||||
|
||||
@@ -109,8 +109,6 @@ def err_fe_expected_clang_command : Error<
|
||||
"expected a clang compiler command">;
|
||||
def err_fe_remap_missing_to_file : Error<
|
||||
"could not remap file '%0' to the contents of file '%1'">, DefaultFatal;
|
||||
def err_fe_remap_missing_from_file : Error<
|
||||
"could not remap from missing file '%0'">, DefaultFatal;
|
||||
def err_fe_unable_to_load_pch : Error<
|
||||
"unable to load PCH file">;
|
||||
def err_fe_unable_to_load_plugin : Error<
|
||||
|
||||
@@ -84,7 +84,7 @@ class FileManager : public RefCountedBase<FileManager> {
|
||||
/// VirtualDirectoryEntries/VirtualFileEntries above.
|
||||
///
|
||||
llvm::StringMap<llvm::ErrorOr<DirectoryEntry &>, llvm::BumpPtrAllocator>
|
||||
SeenDirEntries;
|
||||
SeenDirEntries;
|
||||
|
||||
/// A cache that maps paths to file entries (either real or
|
||||
/// virtual) we have looked up, or an error that occurred when we looked up
|
||||
@@ -190,6 +190,8 @@ public:
|
||||
///
|
||||
/// \param CacheFailure If true and the file does not exist, we'll cache
|
||||
/// the failure to find this file.
|
||||
LLVM_DEPRECATED("Functions returning DirectoryEntry are deprecated.",
|
||||
"getOptionalDirectoryRef()")
|
||||
llvm::ErrorOr<const DirectoryEntry *>
|
||||
getDirectory(StringRef DirName, bool CacheFailure = true);
|
||||
|
||||
@@ -207,6 +209,8 @@ public:
|
||||
///
|
||||
/// \param CacheFailure If true and the file does not exist, we'll cache
|
||||
/// the failure to find this file.
|
||||
LLVM_DEPRECATED("Functions returning FileEntry are deprecated.",
|
||||
"getOptionalFileRef()")
|
||||
llvm::ErrorOr<const FileEntry *>
|
||||
getFile(StringRef Filename, bool OpenFile = false, bool CacheFailure = true);
|
||||
|
||||
@@ -269,6 +273,8 @@ public:
|
||||
FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size,
|
||||
time_t ModificationTime);
|
||||
|
||||
LLVM_DEPRECATED("Functions returning FileEntry are deprecated.",
|
||||
"getVirtualFileRef()")
|
||||
const FileEntry *getVirtualFile(StringRef Filename, off_t Size,
|
||||
time_t ModificationTime);
|
||||
|
||||
|
||||
@@ -10020,8 +10020,8 @@ Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) {
|
||||
ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
|
||||
|
||||
if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
|
||||
// FIXME: We probably want to use getVirtualFile(), so we don't hit the
|
||||
// disk again
|
||||
// FIXME: We probably want to use getVirtualFileRef(), so we don't hit
|
||||
// the disk again
|
||||
// FIXME: We definitely want to re-use the existing MemoryBuffer, rather
|
||||
// than mmap the files several times.
|
||||
auto Entry =
|
||||
|
||||
@@ -586,9 +586,9 @@ const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc(
|
||||
if (D.isLocationAvailable()) {
|
||||
D.getLocation(Filename, Line, Column);
|
||||
if (Line > 0) {
|
||||
auto FE = FileMgr.getFile(Filename);
|
||||
auto FE = FileMgr.getOptionalFileRef(Filename);
|
||||
if (!FE)
|
||||
FE = FileMgr.getFile(D.getAbsolutePath());
|
||||
FE = FileMgr.getOptionalFileRef(D.getAbsolutePath());
|
||||
if (FE) {
|
||||
// If -gcolumn-info was not used, Column will be 0. This upsets the
|
||||
// source manager, so pass 1 if Column is not set.
|
||||
|
||||
@@ -217,8 +217,8 @@ struct LocationFileChecker {
|
||||
SmallVector<std::pair<SmallString<32>, bool>> &KnownFiles)
|
||||
: CI(CI), KnownFiles(KnownFiles), ExternalFileEntries() {
|
||||
for (const auto &KnownFile : KnownFiles)
|
||||
if (auto FileEntry = CI.getFileManager().getFile(KnownFile.first))
|
||||
KnownFileEntries.insert(*FileEntry);
|
||||
if (auto FE = CI.getFileManager().getOptionalFileRef(KnownFile.first))
|
||||
KnownFileEntries.insert(*FE);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -2395,7 +2395,7 @@ void ASTUnit::TranslateStoredDiagnostics(
|
||||
// Rebuild the StoredDiagnostic.
|
||||
if (SD.Filename.empty())
|
||||
continue;
|
||||
auto FE = FileMgr.getFile(SD.Filename);
|
||||
auto FE = FileMgr.getOptionalFileRef(SD.Filename);
|
||||
if (!FE)
|
||||
continue;
|
||||
SourceLocation FileLoc;
|
||||
|
||||
@@ -427,12 +427,8 @@ 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);
|
||||
if (!FromFile) {
|
||||
Diags.Report(diag::err_fe_remap_missing_from_file) << RF.first;
|
||||
continue;
|
||||
}
|
||||
FileEntryRef FromFile =
|
||||
FileMgr.getVirtualFileRef(RF.first, ToFile->getSize(), 0);
|
||||
|
||||
// Override the contents of the "from" file with the contents of
|
||||
// the "to" file.
|
||||
@@ -1926,7 +1922,7 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
|
||||
|
||||
// Check whether M refers to the file in the prebuilt module path.
|
||||
if (M && M->getASTFile())
|
||||
if (auto ModuleFile = FileMgr->getFile(ModuleFilename))
|
||||
if (auto ModuleFile = FileMgr->getOptionalFileRef(ModuleFilename))
|
||||
if (*ModuleFile == M->getASTFile())
|
||||
return M;
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ public:
|
||||
|
||||
void visitModuleFile(StringRef Filename,
|
||||
serialization::ModuleKind Kind) override {
|
||||
auto File = CI.getFileManager().getFile(Filename);
|
||||
auto File = CI.getFileManager().getOptionalFileRef(Filename);
|
||||
assert(File && "missing file for loaded module?");
|
||||
|
||||
// Only rewrite each module file once.
|
||||
|
||||
@@ -107,7 +107,7 @@ InstallAPIContext::findAndRecordFile(const FileEntry *FE,
|
||||
}
|
||||
|
||||
void InstallAPIContext::addKnownHeader(const HeaderFile &H) {
|
||||
auto FE = FM->getFile(H.getPath());
|
||||
auto FE = FM->getOptionalFileRef(H.getPath());
|
||||
if (!FE)
|
||||
return; // File does not exist.
|
||||
KnownFiles[*FE] = H.getType();
|
||||
|
||||
@@ -227,7 +227,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName,
|
||||
".pcm");
|
||||
else
|
||||
llvm::sys::path::append(Result, ModuleName + ".pcm");
|
||||
if (getFileMgr().getFile(Result.str()))
|
||||
if (getFileMgr().getOptionalFileRef(Result))
|
||||
return std::string(Result);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) {
|
||||
llvm::sys::path::append(CachePath, ModuleCacheHash);
|
||||
std::string FileName =
|
||||
getCachedModuleFileNameImpl(ModuleName, ModuleMapPath, CachePath);
|
||||
if (!FileName.empty() && getFileMgr().getFile(FileName))
|
||||
if (!FileName.empty() && getFileMgr().getOptionalFileRef(FileName))
|
||||
return FileName;
|
||||
}
|
||||
return {};
|
||||
@@ -655,7 +655,7 @@ OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup(
|
||||
++NumFrameworkLookups;
|
||||
|
||||
// If the framework dir doesn't exist, we fail.
|
||||
auto Dir = FileMgr.getDirectory(FrameworkName);
|
||||
auto Dir = FileMgr.getOptionalDirectoryRef(FrameworkName);
|
||||
if (!Dir)
|
||||
return std::nullopt;
|
||||
|
||||
@@ -718,7 +718,7 @@ OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup(
|
||||
bool FoundFramework = false;
|
||||
do {
|
||||
// Determine whether this directory exists.
|
||||
auto Dir = FileMgr.getDirectory(FrameworkPath);
|
||||
auto Dir = FileMgr.getOptionalDirectoryRef(FrameworkPath);
|
||||
if (!Dir)
|
||||
break;
|
||||
|
||||
|
||||
@@ -1144,7 +1144,8 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
|
||||
if (SubframeworkDirName.empty())
|
||||
break;
|
||||
|
||||
if (auto SubDir = FileMgr.getDirectory(SubframeworkDirName)) {
|
||||
if (auto SubDir =
|
||||
FileMgr.getOptionalDirectoryRef(SubframeworkDirName)) {
|
||||
if (*SubDir == FrameworkDir) {
|
||||
FoundParent = true;
|
||||
break;
|
||||
|
||||
@@ -229,7 +229,7 @@ static void computeRelativePath(FileManager &FM, const DirectoryEntry *Dir,
|
||||
StringRef FilePath = File.getDir().getName();
|
||||
StringRef Path = FilePath;
|
||||
while (!Path.empty()) {
|
||||
if (auto CurDir = FM.getDirectory(Path)) {
|
||||
if (auto CurDir = FM.getOptionalDirectoryRef(Path)) {
|
||||
if (*CurDir == Dir) {
|
||||
Result = FilePath.substr(Path.size());
|
||||
llvm::sys::path::append(Result,
|
||||
|
||||
@@ -2044,14 +2044,14 @@ ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M,
|
||||
const FileEntry *HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
|
||||
FileManager &FileMgr = Reader.getFileManager();
|
||||
if (!Key.Imported) {
|
||||
if (auto File = FileMgr.getFile(Key.Filename))
|
||||
if (auto File = FileMgr.getOptionalFileRef(Key.Filename))
|
||||
return *File;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string Resolved = std::string(Key.Filename);
|
||||
Reader.ResolveImportedPath(M, Resolved);
|
||||
if (auto File = FileMgr.getFile(Resolved))
|
||||
if (auto File = FileMgr.getOptionalFileRef(Resolved))
|
||||
return *File;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -4217,7 +4217,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
|
||||
assert(M && M->Name == F.ModuleName && "found module with different name");
|
||||
|
||||
// Check the primary module map file.
|
||||
auto StoredModMap = FileMgr.getFile(F.ModuleMapPath);
|
||||
auto StoredModMap = FileMgr.getOptionalFileRef(F.ModuleMapPath);
|
||||
if (!StoredModMap || *StoredModMap != ModMap) {
|
||||
assert(ModMap && "found module is missing module map file");
|
||||
assert((ImportedBy || F.Kind == MK_ImplicitModule) &&
|
||||
|
||||
@@ -42,8 +42,8 @@ using namespace clang;
|
||||
using namespace serialization;
|
||||
|
||||
ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const {
|
||||
auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
|
||||
/*CacheFailure=*/false);
|
||||
auto Entry = FileMgr.getOptionalFileRef(Name, /*OpenFile=*/false,
|
||||
/*CacheFailure=*/false);
|
||||
if (Entry)
|
||||
return lookup(*Entry);
|
||||
|
||||
@@ -64,8 +64,8 @@ ModuleFile *ModuleManager::lookup(const FileEntry *File) const {
|
||||
|
||||
std::unique_ptr<llvm::MemoryBuffer>
|
||||
ModuleManager::lookupBuffer(StringRef Name) {
|
||||
auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false,
|
||||
/*CacheFailure=*/false);
|
||||
auto Entry = FileMgr.getOptionalFileRef(Name, /*OpenFile=*/false,
|
||||
/*CacheFailure=*/false);
|
||||
if (!Entry)
|
||||
return nullptr;
|
||||
return std::move(InMemoryBuffers[*Entry]);
|
||||
@@ -279,8 +279,8 @@ void ModuleManager::removeModules(ModuleIterator First) {
|
||||
void
|
||||
ModuleManager::addInMemoryBuffer(StringRef FileName,
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
const FileEntry *Entry =
|
||||
FileMgr.getVirtualFile(FileName, Buffer->getBufferSize(), 0);
|
||||
FileEntryRef Entry =
|
||||
FileMgr.getVirtualFileRef(FileName, Buffer->getBufferSize(), 0);
|
||||
InMemoryBuffers[Entry] = std::move(Buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -614,7 +614,7 @@ std::map<std::string, Replacements> groupReplacementsByFile(
|
||||
std::map<std::string, Replacements> Result;
|
||||
llvm::SmallPtrSet<const FileEntry *, 16> ProcessedFileEntries;
|
||||
for (const auto &Entry : FileToReplaces) {
|
||||
auto FE = FileMgr.getFile(Entry.first);
|
||||
auto FE = FileMgr.getOptionalFileRef(Entry.first);
|
||||
if (!FE)
|
||||
llvm::errs() << "File path " << Entry.first << " is invalid.\n";
|
||||
else if (ProcessedFileEntries.insert(*FE).second)
|
||||
|
||||
@@ -241,7 +241,7 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
|
||||
ModuleMapInputKind);
|
||||
|
||||
auto CurrentModuleMapEntry =
|
||||
ScanInstance.getFileManager().getFile(Deps.ClangModuleMapFile);
|
||||
ScanInstance.getFileManager().getOptionalFileRef(Deps.ClangModuleMapFile);
|
||||
assert(CurrentModuleMapEntry && "module map file entry not found");
|
||||
|
||||
// Remove directly passed modulemap files. They will get added back if they
|
||||
@@ -251,7 +251,8 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
|
||||
auto DepModuleMapFiles = collectModuleMapFiles(Deps.ClangModuleDeps);
|
||||
for (StringRef ModuleMapFile : Deps.ModuleMapFileDeps) {
|
||||
// TODO: Track these as `FileEntryRef` to simplify the equality check below.
|
||||
auto ModuleMapEntry = ScanInstance.getFileManager().getFile(ModuleMapFile);
|
||||
auto ModuleMapEntry =
|
||||
ScanInstance.getFileManager().getOptionalFileRef(ModuleMapFile);
|
||||
assert(ModuleMapEntry && "module map file entry not found");
|
||||
|
||||
// Don't report module maps describing eagerly-loaded dependency. This
|
||||
@@ -299,7 +300,8 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
|
||||
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
|
||||
assert(MD && "Inconsistent dependency info");
|
||||
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
|
||||
auto FE = ScanInstance.getFileManager().getFile(MD->ClangModuleMapFile);
|
||||
auto FE = ScanInstance.getFileManager().getOptionalFileRef(
|
||||
MD->ClangModuleMapFile);
|
||||
assert(FE && "Missing module map file that was previously found");
|
||||
ModuleMapFiles.insert(*FE);
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ bool Options::processFrontendOptions(InputArgList &Args) {
|
||||
bool Options::addFilePaths(InputArgList &Args, PathSeq &Headers,
|
||||
OptSpecifier ID) {
|
||||
for (const StringRef Path : Args.getAllArgValues(ID)) {
|
||||
if ((bool)FM->getDirectory(Path, /*CacheFailure=*/false)) {
|
||||
if ((bool)FM->getOptionalDirectoryRef(Path, /*CacheFailure=*/false)) {
|
||||
auto InputHeadersOrErr = enumerateFiles(*FM, Path);
|
||||
if (!InputHeadersOrErr) {
|
||||
Diags->Report(diag::err_cannot_open_file)
|
||||
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
|
||||
bool forAllRanges(const SourceManager &SM,
|
||||
llvm::function_ref<void(SourceRange R)> Callback) override {
|
||||
auto FE = SM.getFileManager().getFile(Range.FileName);
|
||||
auto FE = SM.getFileManager().getOptionalFileRef(Range.FileName);
|
||||
FileID FID = FE ? SM.translateFile(*FE) : FileID();
|
||||
if (!FE || FID.isInvalid()) {
|
||||
llvm::errs() << "error: -selection=" << Range.FileName
|
||||
|
||||
@@ -43,7 +43,7 @@ void TestSelectionRangesInFile::dump(raw_ostream &OS) const {
|
||||
bool TestSelectionRangesInFile::foreachRange(
|
||||
const SourceManager &SM,
|
||||
llvm::function_ref<void(SourceRange)> Callback) const {
|
||||
auto FE = SM.getFileManager().getFile(Filename);
|
||||
auto FE = SM.getFileManager().getOptionalFileRef(Filename);
|
||||
FileID FID = FE ? SM.translateFile(*FE) : FileID();
|
||||
if (!FE || FID.isInvalid()) {
|
||||
llvm::errs() << "error: -selection=test:" << Filename
|
||||
|
||||
@@ -116,9 +116,9 @@ TEST_F(FileManagerTest, NoVirtualDirectoryExistsBeforeAVirtualFileIsAdded) {
|
||||
// by what's in the real file system.
|
||||
manager.setStatCache(std::make_unique<FakeStatCache>());
|
||||
|
||||
ASSERT_FALSE(manager.getDirectory("virtual/dir/foo"));
|
||||
ASSERT_FALSE(manager.getDirectory("virtual/dir"));
|
||||
ASSERT_FALSE(manager.getDirectory("virtual"));
|
||||
ASSERT_FALSE(manager.getOptionalDirectoryRef("virtual/dir/foo"));
|
||||
ASSERT_FALSE(manager.getOptionalDirectoryRef("virtual/dir"));
|
||||
ASSERT_FALSE(manager.getOptionalDirectoryRef("virtual"));
|
||||
}
|
||||
|
||||
// When a virtual file is added, all of its ancestors should be created.
|
||||
@@ -126,10 +126,12 @@ TEST_F(FileManagerTest, getVirtualFileCreatesDirectoryEntriesForAncestors) {
|
||||
// Fake an empty real file system.
|
||||
manager.setStatCache(std::make_unique<FakeStatCache>());
|
||||
|
||||
manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
|
||||
ASSERT_FALSE(manager.getDirectory("virtual/dir/foo"));
|
||||
manager.getVirtualFileRef("virtual/dir/bar.h", 100, 0);
|
||||
|
||||
auto dir = manager.getDirectoryRef("virtual/dir");
|
||||
auto dir = manager.getDirectoryRef("virtual/dir/foo");
|
||||
ASSERT_THAT_EXPECTED(dir, llvm::Failed());
|
||||
|
||||
dir = manager.getDirectoryRef("virtual/dir");
|
||||
ASSERT_THAT_EXPECTED(dir, llvm::Succeeded());
|
||||
EXPECT_EQ("virtual/dir", dir->getName());
|
||||
|
||||
@@ -172,7 +174,7 @@ TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingVirtualFile) {
|
||||
// Fake an empty real file system.
|
||||
manager.setStatCache(std::make_unique<FakeStatCache>());
|
||||
|
||||
manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
|
||||
manager.getVirtualFileRef("virtual/dir/bar.h", 100, 0);
|
||||
auto file = manager.getFileRef("virtual/dir/bar.h");
|
||||
ASSERT_THAT_EXPECTED(file, llvm::Succeeded());
|
||||
EXPECT_EQ("virtual/dir/bar.h", file->getName());
|
||||
@@ -190,11 +192,11 @@ TEST_F(FileManagerTest, getFileReturnsDifferentFileEntriesForDifferentFiles) {
|
||||
statCache->InjectFile("bar.cpp", 43);
|
||||
manager.setStatCache(std::move(statCache));
|
||||
|
||||
auto fileFoo = manager.getFile("foo.cpp");
|
||||
auto fileBar = manager.getFile("bar.cpp");
|
||||
auto fileFoo = manager.getOptionalFileRef("foo.cpp");
|
||||
auto fileBar = manager.getOptionalFileRef("bar.cpp");
|
||||
ASSERT_TRUE(fileFoo);
|
||||
ASSERT_TRUE(fileBar);
|
||||
EXPECT_NE(*fileFoo, *fileBar);
|
||||
EXPECT_NE(&fileFoo->getFileEntry(), &fileBar->getFileEntry());
|
||||
}
|
||||
|
||||
// getFile() returns an error if neither a real file nor a virtual file
|
||||
@@ -208,19 +210,22 @@ TEST_F(FileManagerTest, getFileReturnsErrorForNonexistentFile) {
|
||||
manager.setStatCache(std::move(statCache));
|
||||
|
||||
// Create a virtual bar.cpp file.
|
||||
manager.getVirtualFile("bar.cpp", 200, 0);
|
||||
manager.getVirtualFileRef("bar.cpp", 200, 0);
|
||||
|
||||
auto file = manager.getFile("xyz.txt");
|
||||
auto file = manager.getFileRef("xyz.txt");
|
||||
ASSERT_FALSE(file);
|
||||
ASSERT_EQ(file.getError(), std::errc::no_such_file_or_directory);
|
||||
ASSERT_EQ(llvm::errorToErrorCode(file.takeError()),
|
||||
std::make_error_code(std::errc::no_such_file_or_directory));
|
||||
|
||||
auto readingDirAsFile = manager.getFile("MyDirectory");
|
||||
auto readingDirAsFile = manager.getFileRef("MyDirectory");
|
||||
ASSERT_FALSE(readingDirAsFile);
|
||||
ASSERT_EQ(readingDirAsFile.getError(), std::errc::is_a_directory);
|
||||
ASSERT_EQ(llvm::errorToErrorCode(readingDirAsFile.takeError()),
|
||||
std::make_error_code(std::errc::is_a_directory));
|
||||
|
||||
auto readingFileAsDir = manager.getDirectory("foo.cpp");
|
||||
auto readingFileAsDir = manager.getDirectoryRef("foo.cpp");
|
||||
ASSERT_FALSE(readingFileAsDir);
|
||||
ASSERT_EQ(readingFileAsDir.getError(), std::errc::not_a_directory);
|
||||
ASSERT_EQ(llvm::errorToErrorCode(readingFileAsDir.takeError()),
|
||||
std::make_error_code(std::errc::not_a_directory));
|
||||
}
|
||||
|
||||
// The following tests apply to Unix-like system only.
|
||||
@@ -236,11 +241,11 @@ TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedRealFiles) {
|
||||
statCache->InjectFile("abc/bar.cpp", 42);
|
||||
manager.setStatCache(std::move(statCache));
|
||||
|
||||
auto f1 = manager.getFile("abc/foo.cpp");
|
||||
auto f2 = manager.getFile("abc/bar.cpp");
|
||||
auto f1 = manager.getOptionalFileRef("abc/foo.cpp");
|
||||
auto f2 = manager.getOptionalFileRef("abc/bar.cpp");
|
||||
|
||||
EXPECT_EQ(f1 ? *f1 : nullptr,
|
||||
f2 ? *f2 : nullptr);
|
||||
EXPECT_EQ(f1 ? &f1->getFileEntry() : nullptr,
|
||||
f2 ? &f2->getFileEntry() : nullptr);
|
||||
|
||||
// Check that getFileRef also does the right thing.
|
||||
auto r1 = manager.getFileRef("abc/foo.cpp");
|
||||
@@ -338,11 +343,11 @@ TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedVirtualFiles) {
|
||||
statCache->InjectFile("abc/bar.cpp", 42);
|
||||
manager.setStatCache(std::move(statCache));
|
||||
|
||||
auto f1 = manager.getFile("abc/foo.cpp");
|
||||
auto f2 = manager.getFile("abc/bar.cpp");
|
||||
auto f1 = manager.getOptionalFileRef("abc/foo.cpp");
|
||||
auto f2 = manager.getOptionalFileRef("abc/bar.cpp");
|
||||
|
||||
EXPECT_EQ(f1 ? *f1 : nullptr,
|
||||
f2 ? *f2 : nullptr);
|
||||
EXPECT_EQ(f1 ? &f1->getFileEntry() : nullptr,
|
||||
f2 ? &f2->getFileEntry() : nullptr);
|
||||
}
|
||||
|
||||
TEST_F(FileManagerTest, getFileRefEquality) {
|
||||
@@ -420,20 +425,19 @@ TEST_F(FileManagerTest, getVirtualFileWithDifferentName) {
|
||||
manager.setStatCache(std::move(statCache));
|
||||
|
||||
// Inject the virtual file:
|
||||
const FileEntry *file1 = manager.getVirtualFile("c:\\tmp\\test", 123, 1);
|
||||
ASSERT_TRUE(file1 != nullptr);
|
||||
EXPECT_EQ(43U, file1->getUniqueID().getFile());
|
||||
EXPECT_EQ(123, file1->getSize());
|
||||
FileEntryRef file1 = manager.getVirtualFileRef("c:\\tmp\\test", 123, 1);
|
||||
EXPECT_EQ(43U, file1.getUniqueID().getFile());
|
||||
EXPECT_EQ(123, file1.getSize());
|
||||
|
||||
// Lookup the virtual file with a different name:
|
||||
auto file2 = manager.getFile("c:/tmp/test", 100, 1);
|
||||
auto file2 = manager.getOptionalFileRef("c:/tmp/test", 100, 1);
|
||||
ASSERT_TRUE(file2);
|
||||
// Check that it's the same UFE:
|
||||
EXPECT_EQ(file1, *file2);
|
||||
EXPECT_EQ(43U, (*file2)->getUniqueID().getFile());
|
||||
EXPECT_EQ(43U, file2->getUniqueID().getFile());
|
||||
// Check that the contents of the UFE are not overwritten by the entry in the
|
||||
// filesystem:
|
||||
EXPECT_EQ(123, (*file2)->getSize());
|
||||
EXPECT_EQ(123, file2->getSize());
|
||||
}
|
||||
|
||||
#endif // !_WIN32
|
||||
@@ -487,12 +491,11 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) {
|
||||
Manager.setStatCache(std::move(statCache));
|
||||
|
||||
// Check for real path.
|
||||
const FileEntry *file = Manager.getVirtualFile("/tmp/test", 123, 1);
|
||||
ASSERT_TRUE(file != nullptr);
|
||||
FileEntryRef file = Manager.getVirtualFileRef("/tmp/test", 123, 1);
|
||||
SmallString<64> ExpectedResult = CustomWorkingDir;
|
||||
|
||||
llvm::sys::path::append(ExpectedResult, "tmp", "test");
|
||||
EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
|
||||
EXPECT_EQ(file.getFileEntry().tryGetRealPathName(), ExpectedResult);
|
||||
}
|
||||
|
||||
TEST_F(FileManagerTest, getFileDontOpenRealPath) {
|
||||
@@ -514,12 +517,12 @@ TEST_F(FileManagerTest, getFileDontOpenRealPath) {
|
||||
Manager.setStatCache(std::move(statCache));
|
||||
|
||||
// Check for real path.
|
||||
auto file = Manager.getFile("/tmp/test", /*OpenFile=*/false);
|
||||
auto file = Manager.getOptionalFileRef("/tmp/test", /*OpenFile=*/false);
|
||||
ASSERT_TRUE(file);
|
||||
SmallString<64> ExpectedResult = CustomWorkingDir;
|
||||
|
||||
llvm::sys::path::append(ExpectedResult, "tmp", "test");
|
||||
EXPECT_EQ((*file)->tryGetRealPathName(), ExpectedResult);
|
||||
EXPECT_EQ(file->getFileEntry().tryGetRealPathName(), ExpectedResult);
|
||||
}
|
||||
|
||||
TEST_F(FileManagerTest, getBypassFile) {
|
||||
|
||||
@@ -549,7 +549,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
|
||||
// These are different than normal includes since predefines buffer doesn't
|
||||
// have a valid insertion location.
|
||||
PP.setPredefines("#include \"/implicit-header.h\"");
|
||||
FileMgr.getVirtualFile("/implicit-header.h", 0, 0);
|
||||
FileMgr.getVirtualFileRef("/implicit-header.h", 0, 0);
|
||||
PP.Initialize(*Target);
|
||||
PP.EnterMainSourceFile();
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ TEST(CompilerInstance, DefaultVFSOverlayFromInvocation) {
|
||||
|
||||
// Check if the virtual file exists which means that our VFS is used by the
|
||||
// CompilerInstance.
|
||||
ASSERT_TRUE(Instance.getFileManager().getFile("vfs-virtual.file"));
|
||||
ASSERT_TRUE(Instance.getFileManager().getOptionalFileRef("vfs-virtual.file"));
|
||||
}
|
||||
|
||||
TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
|
||||
|
||||
Reference in New Issue
Block a user