Skip to content

Commit f94695b

Browse files
committed
[clang] NFCI: Use FileEntryRef in FileManager::getBufferForFile()
1 parent 7e013d6 commit f94695b

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

clang/include/clang/Basic/FileManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class FileManager : public RefCountedBase<FileManager> {
275275
/// Open the specified file as a MemoryBuffer, returning a new
276276
/// MemoryBuffer if successful, otherwise returning null.
277277
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
278-
getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
278+
getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
279279
bool RequiresNullTerminator = true);
280280
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
281281
getBufferForFile(StringRef Filename, bool isVolatile = false,

clang/include/clang/Lex/HeaderMap.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ class HeaderMap : private HeaderMapImpl {
8888
public:
8989
/// This attempts to load the specified file as a header map. If it doesn't
9090
/// look like a HeaderMap, it gives up and returns null.
91-
static std::unique_ptr<HeaderMap> Create(const FileEntry *FE,
92-
FileManager &FM);
91+
static std::unique_ptr<HeaderMap> Create(FileEntryRef FE, FileManager &FM);
9392

9493
using HeaderMapImpl::dump;
9594
using HeaderMapImpl::forEachKey;

clang/lib/Basic/FileManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,9 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
536536
}
537537

538538
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
539-
FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
539+
FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
540540
bool RequiresNullTerminator) {
541+
const FileEntry *Entry = &FE.getFileEntry();
541542
// If the content is living on the file entry, return a reference to it.
542543
if (Entry->Content)
543544
return llvm::MemoryBuffer::getMemBuffer(Entry->Content->getMemBufferRef());
@@ -548,7 +549,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
548549
if (isVolatile || Entry->isNamedPipe())
549550
FileSize = -1;
550551

551-
StringRef Filename = Entry->getName();
552+
StringRef Filename = FE.getName();
552553
// If the file is already open, use the open file descriptor.
553554
if (Entry->File) {
554555
auto Result = Entry->File->getBuffer(Filename, FileSize,

clang/lib/Lex/HeaderMap.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ static inline unsigned HashHMapKey(StringRef Str) {
4848
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
4949
/// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
5050
/// into the string error argument and returns null.
51-
std::unique_ptr<HeaderMap> HeaderMap::Create(const FileEntry *FE,
52-
FileManager &FM) {
51+
std::unique_ptr<HeaderMap> HeaderMap::Create(FileEntryRef FE, FileManager &FM) {
5352
// If the file is too small to be a header map, ignore it.
54-
unsigned FileSize = FE->getSize();
53+
unsigned FileSize = FE.getSize();
5554
if (FileSize <= sizeof(HMapHeader)) return nullptr;
5655

5756
auto FileBuffer = FM.getBufferForFile(FE);

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
25012501
// accept the cached file as legit.
25022502
if (ValidateASTInputFilesContent &&
25032503
StoredContentHash != static_cast<uint64_t>(llvm::hash_code(-1))) {
2504-
auto MemBuffOrError = FileMgr.getBufferForFile(File);
2504+
auto MemBuffOrError = FileMgr.getBufferForFile(*File);
25052505
if (!MemBuffOrError) {
25062506
if (!Complain)
25072507
return MTimeChange;

clang/lib/Serialization/ModuleManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
209209
//
210210
// RequiresNullTerminator is false because module files don't need it, and
211211
// this allows the file to still be mmapped.
212-
Buf = FileMgr.getBufferForFile(NewModule->File,
212+
Buf = FileMgr.getBufferForFile(*NewModule->File,
213213
/*IsVolatile=*/true,
214214
/*RequiresNullTerminator=*/false);
215215
}

clang/unittests/Lex/HeaderSearchTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class HeaderSearchTest : public ::testing::Test {
6767
VFS->addFile(Filename, 0, std::move(Buf), /*User=*/std::nullopt,
6868
/*Group=*/std::nullopt,
6969
llvm::sys::fs::file_type::regular_file);
70-
auto FE = FileMgr.getFile(Filename, true);
70+
auto FE = FileMgr.getOptionalFileRef(Filename, true);
7171
assert(FE);
7272

7373
// Test class supports only one HMap at a time.

0 commit comments

Comments
 (0)