Skip to content

Commit

Permalink
[MC] Plumb unique_ptr<MCWinCOFFObjectTargetWriter> through
Browse files Browse the repository at this point in the history
createWinCOFFObjectWriter to WinCOFFObjectWriter's constructor.

Fixes the same ownership issue for COFF that r315245 did for MachO:
WinCOFFObjectWriter takes ownership of its MCWinCOFFObjectTargetWriter, so we
want to pass this through to the constructor via a unique_ptr, rather than a
raw ptr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315257 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lhames committed Oct 10, 2017
1 parent 37437af commit 1d8cdbb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions include/llvm/MC/MCWinCOFFObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class raw_pwrite_stream;
/// \param MOTW - The target specific WinCOFF writer subclass.
/// \param OS - The stream to write to.
/// \returns The constructed object writer.
MCObjectWriter *createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS);
MCObjectWriter *
createWinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS);
} // end namespace llvm

#endif // LLVM_MC_MCWINCOFFOBJECTWRITER_H
16 changes: 8 additions & 8 deletions lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class WinCOFFObjectWriter : public MCObjectWriter {

bool UseBigObj;

WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW, raw_pwrite_stream &OS);
WinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
raw_pwrite_stream &OS);

void reset() override {
memset(&Header, 0, sizeof(Header));
Expand Down Expand Up @@ -222,9 +223,9 @@ void COFFSymbol::set_name_offset(uint32_t Offset) {
//------------------------------------------------------------------------------
// WinCOFFObjectWriter class implementation

WinCOFFObjectWriter::WinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS)
: MCObjectWriter(OS, true), TargetObjectWriter(MOTW) {
WinCOFFObjectWriter::WinCOFFObjectWriter(
std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS)
: MCObjectWriter(OS, true), TargetObjectWriter(std::move(MOTW)) {
Header.Machine = TargetObjectWriter->getMachine();
}

Expand Down Expand Up @@ -1084,8 +1085,7 @@ void MCWinCOFFObjectTargetWriter::anchor() {}
//------------------------------------------------------------------------------
// WinCOFFObjectWriter factory function

MCObjectWriter *
llvm::createWinCOFFObjectWriter(MCWinCOFFObjectTargetWriter *MOTW,
raw_pwrite_stream &OS) {
return new WinCOFFObjectWriter(MOTW, OS);
MCObjectWriter *llvm::createWinCOFFObjectWriter(
std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS) {
return new WinCOFFObjectWriter(std::move(MOTW), OS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ bool AArch64WinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
namespace llvm {

MCObjectWriter *createAArch64WinCOFFObjectWriter(raw_pwrite_stream &OS) {
MCWinCOFFObjectTargetWriter *MOTW = new AArch64WinCOFFObjectWriter();
return createWinCOFFObjectWriter(MOTW, OS);
auto MOTW = llvm::make_unique<AArch64WinCOFFObjectWriter>();
return createWinCOFFObjectWriter(std::move(MOTW), OS);
}

} // end namespace llvm
4 changes: 2 additions & 2 deletions lib/Target/ARM/MCTargetDesc/ARMWinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ namespace llvm {

MCObjectWriter *createARMWinCOFFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit) {
MCWinCOFFObjectTargetWriter *MOTW = new ARMWinCOFFObjectWriter(Is64Bit);
return createWinCOFFObjectWriter(MOTW, OS);
auto MOTW = llvm::make_unique<ARMWinCOFFObjectWriter>(Is64Bit);
return createWinCOFFObjectWriter(std::move(MOTW), OS);
}

} // end namespace llvm
4 changes: 2 additions & 2 deletions lib/Target/X86/MCTargetDesc/X86WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ unsigned X86WinCOFFObjectWriter::getRelocType(MCContext &Ctx,

MCObjectWriter *llvm::createX86WinCOFFObjectWriter(raw_pwrite_stream &OS,
bool Is64Bit) {
MCWinCOFFObjectTargetWriter *MOTW = new X86WinCOFFObjectWriter(Is64Bit);
return createWinCOFFObjectWriter(MOTW, OS);
auto MOTW = llvm::make_unique<X86WinCOFFObjectWriter>(Is64Bit);
return createWinCOFFObjectWriter(std::move(MOTW), OS);
}

0 comments on commit 1d8cdbb

Please sign in to comment.