Skip to content

Commit

Permalink
Use zero-initialization instead of memset.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295119 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rui314 committed Feb 14, 2017
1 parent 8a5fe48 commit 3afdebf
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class COFFSection;

class COFFSymbol {
public:
COFF::symbol Data;
COFF::symbol Data = {};

typedef SmallVector<AuxSymbol, 1> AuxiliarySymbols;

Expand All @@ -84,7 +84,7 @@ class COFFSymbol {
int Relocations = 0;
const MCSymbol *MC = nullptr;

COFFSymbol(StringRef name);
COFFSymbol(StringRef Name) : Name(Name) {}

void set_name_offset(uint32_t Offset);

Expand All @@ -110,15 +110,15 @@ typedef std::vector<COFFRelocation> relocations;

class COFFSection {
public:
COFF::section Header;
COFF::section Header = {};

std::string Name;
int Number;
MCSectionCOFF const *MCSection = nullptr;
COFFSymbol *Symbol = nullptr;
relocations Relocations;

COFFSection(StringRef name);
COFFSection(StringRef Name) : Name(Name) {}
};

class WinCOFFObjectWriter : public MCObjectWriter {
Expand All @@ -132,7 +132,7 @@ class WinCOFFObjectWriter : public MCObjectWriter {
std::unique_ptr<MCWinCOFFObjectTargetWriter> TargetObjectWriter;

// Root level file contents.
COFF::header Header;
COFF::header Header = {};
sections Sections;
symbols Symbols;
StringTableBuilder Strings{StringTableBuilder::WinCOFF};
Expand Down Expand Up @@ -212,10 +212,6 @@ static inline void write_uint32_le(void *Data, uint32_t Value) {
//------------------------------------------------------------------------------
// Symbol class implementation

COFFSymbol::COFFSymbol(StringRef name) : Name(name.begin(), name.end()) {
memset(&Data, 0, sizeof(Data));
}

// In the case that the name does not fit within 8 bytes, the offset
// into the string table is stored in the last 4 bytes instead, leaving
// the first 4 bytes as 0.
Expand All @@ -224,21 +220,12 @@ void COFFSymbol::set_name_offset(uint32_t Offset) {
write_uint32_le(Data.Name + 4, Offset);
}

//------------------------------------------------------------------------------
// Section class implementation

COFFSection::COFFSection(StringRef name) : Name(name) {
memset(&Header, 0, sizeof(Header));
}

//------------------------------------------------------------------------------
// WinCOFFObjectWriter class implementation

WinCOFFObjectWriter::WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS)
: MCObjectWriter(OS, true), TargetObjectWriter(MOTW) {
memset(&Header, 0, sizeof(Header));

Header.Machine = TargetObjectWriter->getMachine();
}

Expand Down

0 comments on commit 3afdebf

Please sign in to comment.