[clang] f94695b - [clang] NFCI: Use `FileEntryRef` in `FileManager::getBufferForFile()`

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 13 15:02:29 PDT 2023


Author: Jan Svoboda
Date: 2023-09-13T15:02:20-07:00
New Revision: f94695b6eb0e0b2bb059c33903cc7dd4a3ddd47f

URL: https://github.com/llvm/llvm-project/commit/f94695b6eb0e0b2bb059c33903cc7dd4a3ddd47f
DIFF: https://github.com/llvm/llvm-project/commit/f94695b6eb0e0b2bb059c33903cc7dd4a3ddd47f.diff

LOG: [clang] NFCI: Use `FileEntryRef` in `FileManager::getBufferForFile()`

Added: 
    

Modified: 
    clang/include/clang/Basic/FileManager.h
    clang/include/clang/Lex/HeaderMap.h
    clang/lib/Basic/FileManager.cpp
    clang/lib/Lex/HeaderMap.cpp
    clang/lib/Serialization/ASTReader.cpp
    clang/lib/Serialization/ModuleManager.cpp
    clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h
index 58ff42ee5c24167..56c45e3cf68cd43 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -275,7 +275,7 @@ class FileManager : public RefCountedBase<FileManager> {
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-  getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
+  getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
                    bool RequiresNullTerminator = true);
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   getBufferForFile(StringRef Filename, bool isVolatile = false,

diff  --git a/clang/include/clang/Lex/HeaderMap.h b/clang/include/clang/Lex/HeaderMap.h
index de753cbfec3ce4e..9d88b36bfd8e41b 100644
--- a/clang/include/clang/Lex/HeaderMap.h
+++ b/clang/include/clang/Lex/HeaderMap.h
@@ -88,8 +88,7 @@ class HeaderMap : private HeaderMapImpl {
 public:
   /// This attempts to load the specified file as a header map.  If it doesn't
   /// look like a HeaderMap, it gives up and returns null.
-  static std::unique_ptr<HeaderMap> Create(const FileEntry *FE,
-                                           FileManager &FM);
+  static std::unique_ptr<HeaderMap> Create(FileEntryRef FE, FileManager &FM);
 
   using HeaderMapImpl::dump;
   using HeaderMapImpl::forEachKey;

diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index c3eec80caaf301c..30e2916c7f2a7f1 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -536,8 +536,9 @@ void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
 }
 
 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
-FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
+FileManager::getBufferForFile(FileEntryRef FE, bool isVolatile,
                               bool RequiresNullTerminator) {
+  const FileEntry *Entry = &FE.getFileEntry();
   // If the content is living on the file entry, return a reference to it.
   if (Entry->Content)
     return llvm::MemoryBuffer::getMemBuffer(Entry->Content->getMemBufferRef());
@@ -548,7 +549,7 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
   if (isVolatile || Entry->isNamedPipe())
     FileSize = -1;
 
-  StringRef Filename = Entry->getName();
+  StringRef Filename = FE.getName();
   // If the file is already open, use the open file descriptor.
   if (Entry->File) {
     auto Result = Entry->File->getBuffer(Filename, FileSize,

diff  --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index da0b8898f6900d4..2b2642673586054 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -48,10 +48,9 @@ static inline unsigned HashHMapKey(StringRef Str) {
 /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
 /// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
 /// into the string error argument and returns null.
-std::unique_ptr<HeaderMap> HeaderMap::Create(const FileEntry *FE,
-                                             FileManager &FM) {
+std::unique_ptr<HeaderMap> HeaderMap::Create(FileEntryRef FE, FileManager &FM) {
   // If the file is too small to be a header map, ignore it.
-  unsigned FileSize = FE->getSize();
+  unsigned FileSize = FE.getSize();
   if (FileSize <= sizeof(HMapHeader)) return nullptr;
 
   auto FileBuffer = FM.getBufferForFile(FE);

diff  --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 2289edc511e9612..6842c0da79c44ef 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2501,7 +2501,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
       // accept the cached file as legit.
       if (ValidateASTInputFilesContent &&
           StoredContentHash != static_cast<uint64_t>(llvm::hash_code(-1))) {
-        auto MemBuffOrError = FileMgr.getBufferForFile(File);
+        auto MemBuffOrError = FileMgr.getBufferForFile(*File);
         if (!MemBuffOrError) {
           if (!Complain)
             return MTimeChange;

diff  --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index 112d27e179dc3d0..de4cd3d05853ac0 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -209,7 +209,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
       //
       // RequiresNullTerminator is false because module files don't need it, and
       // this allows the file to still be mmapped.
-      Buf = FileMgr.getBufferForFile(NewModule->File,
+      Buf = FileMgr.getBufferForFile(*NewModule->File,
                                      /*IsVolatile=*/true,
                                      /*RequiresNullTerminator=*/false);
     }

diff  --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index cc30b0a4304ff3c..c578fa72c859e08 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -67,7 +67,7 @@ class HeaderSearchTest : public ::testing::Test {
     VFS->addFile(Filename, 0, std::move(Buf), /*User=*/std::nullopt,
                  /*Group=*/std::nullopt,
                  llvm::sys::fs::file_type::regular_file);
-    auto FE = FileMgr.getFile(Filename, true);
+    auto FE = FileMgr.getOptionalFileRef(Filename, true);
     assert(FE);
 
     // Test class supports only one HMap at a time.


        


More information about the cfe-commits mailing list