Skip to content

Commit 2375921

Browse files
[ProfileData] Use default member initializations (NFC) (#93120)
This patch uses default member initializations for all the fields in Header. The intent is to prevent accidental uninitialized fields and reduce the number of times we need to mention each member variable.
1 parent aa4069e commit 2375921

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,21 +1184,21 @@ inline uint64_t ComputeHash(StringRef K) { return ComputeHash(HashType, K); }
11841184
// data file in indexed-format. Please update llvm/docs/InstrProfileFormat.rst
11851185
// as appropriate when updating the indexed profile format.
11861186
struct Header {
1187-
uint64_t Magic;
1187+
uint64_t Magic = IndexedInstrProf::Magic;
11881188
// The lower 32 bits specify the version of the indexed profile.
11891189
// The most significant 32 bits are reserved to specify the variant types of
11901190
// the profile.
1191-
uint64_t Version;
1192-
uint64_t Unused; // Becomes unused since version 4
1193-
uint64_t HashType;
1191+
uint64_t Version = 0;
1192+
uint64_t Unused = 0; // Becomes unused since version 4
1193+
uint64_t HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
11941194
// This field records the offset of this hash table's metadata (i.e., the
11951195
// number of buckets and entries), which follows right after the payload of
11961196
// the entire hash table.
1197-
uint64_t HashOffset;
1198-
uint64_t MemProfOffset;
1199-
uint64_t BinaryIdOffset;
1200-
uint64_t TemporalProfTracesOffset;
1201-
uint64_t VTableNamesOffset;
1197+
uint64_t HashOffset = 0;
1198+
uint64_t MemProfOffset = 0;
1199+
uint64_t BinaryIdOffset = 0;
1200+
uint64_t TemporalProfTracesOffset = 0;
1201+
uint64_t VTableNamesOffset = 0;
12021202
// New fields should only be added at the end to ensure that the size
12031203
// computation is correct. The methods below need to be updated to ensure that
12041204
// the new field is read correctly.

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
682682

683683
// Write the header.
684684
IndexedInstrProf::Header Header;
685-
Header.Magic = IndexedInstrProf::Magic;
686685
Header.Version = WritePrevVersion
687686
? IndexedInstrProf::ProfVersion::Version11
688687
: IndexedInstrProf::ProfVersion::CurrentVersion;
@@ -706,14 +705,6 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
706705
if (static_cast<bool>(ProfileKind & InstrProfKind::TemporalProfile))
707706
Header.Version |= VARIANT_MASK_TEMPORAL_PROF;
708707

709-
Header.Unused = 0;
710-
Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
711-
Header.HashOffset = 0;
712-
Header.MemProfOffset = 0;
713-
Header.BinaryIdOffset = 0;
714-
Header.TemporalProfTracesOffset = 0;
715-
Header.VTableNamesOffset = 0;
716-
717708
const uint64_t BackPatchStartOffset =
718709
writeHeader(Header, WritePrevVersion, OS);
719710

0 commit comments

Comments
 (0)