[llvm-branch-commits] [clang] 0978c83 - Basic: Initialize FileEntry's fields inline, almost NFC

Duncan P. N. Exon Smith via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 10 14:01:56 PST 2020


Author: Duncan P. N. Exon Smith
Date: 2020-12-10T13:57:21-08:00
New Revision: 0978c83e6fcc7a8aea18e24eb3b2ad5523581757

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

LOG: Basic: Initialize FileEntry's fields inline, almost NFC

Initialize most of FileEntry's fields inline (all the ones that can be).
The only functionality change is to avoid leaving some fields
uninitialized.

Added: 
    

Modified: 
    clang/include/clang/Basic/FileEntry.h
    clang/lib/Basic/FileEntry.cpp
    clang/unittests/Basic/FileEntryTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index 8db5446aa8d4..aa7bedec44ac 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -328,13 +328,13 @@ class FileEntry {
   friend class FileManager;
 
   std::string RealPathName;   // Real path to the file; could be empty.
-  off_t Size;                 // File size in bytes.
-  time_t ModTime;             // Modification time of file.
-  const DirectoryEntry *Dir;  // Directory file lives in.
+  off_t Size = 0;             // File size in bytes.
+  time_t ModTime = 0;         // Modification time of file.
+  const DirectoryEntry *Dir = nullptr; // Directory file lives in.
   llvm::sys::fs::UniqueID UniqueID;
-  unsigned UID;               // A unique (small) ID for the file.
-  bool IsNamedPipe;
-  bool IsValid;               // Is this \c FileEntry initialized and valid?
+  unsigned UID = 0; // A unique (small) ID for the file.
+  bool IsNamedPipe = false;
+  bool IsValid = false; // Is this \c FileEntry initialized and valid?
 
   /// The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr<llvm::vfs::File> File;

diff  --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp
index 29218c7e0ec8..2efdcbbd46aa 100644
--- a/clang/lib/Basic/FileEntry.cpp
+++ b/clang/lib/Basic/FileEntry.cpp
@@ -16,7 +16,7 @@
 
 using namespace clang;
 
-FileEntry::FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) {}
+FileEntry::FileEntry() : UniqueID(0, 0) {}
 
 FileEntry::~FileEntry() = default;
 

diff  --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp
index 3cc01870b800..a3e03e6c7c29 100644
--- a/clang/unittests/Basic/FileEntryTest.cpp
+++ b/clang/unittests/Basic/FileEntryTest.cpp
@@ -55,6 +55,17 @@ struct RefMaps {
   }
 };
 
+TEST(FileEntryTest, Constructor) {
+  FileEntry FE;
+  EXPECT_EQ(0U, FE.getSize());
+  EXPECT_EQ(0, FE.getModificationTime());
+  EXPECT_EQ(nullptr, FE.getDir());
+  EXPECT_EQ(0U, FE.getUniqueID().getDevice());
+  EXPECT_EQ(0U, FE.getUniqueID().getFile());
+  EXPECT_EQ(false, FE.isNamedPipe());
+  EXPECT_EQ(false, FE.isValid());
+}
+
 TEST(FileEntryTest, FileEntryRef) {
   RefMaps Refs;
   FileEntryRef R1 = Refs.addFile("1");


        


More information about the llvm-branch-commits mailing list