]> granicus.if.org Git - llvm/commitdiff
[MC] Plumb unique_ptr<MCWasmObjectTargetWriter> through createWasmObjectWriter
authorLang Hames <lhames@gmail.com>
Tue, 10 Oct 2017 01:15:10 +0000 (01:15 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 10 Oct 2017 01:15:10 +0000 (01:15 +0000)
to WasmObjectWriter's constructor.

Fixes the same ownership issue for COFF that r315245 did for MachO:
WasmObjectWriter takes ownership of its MCWasmObjectTargetWriter, 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@315260 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCWasmObjectWriter.h
lib/MC/WasmObjectWriter.cpp
lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp

index bebc0a8258100f1418a5732cea597d755c2c7ac2..5ddb18b8e3889594a9f38b98bac7a1a7420aa530 100644 (file)
@@ -44,8 +44,9 @@ public:
 /// \param MOTW - The target specific Wasm writer subclass.
 /// \param OS - The stream to write to.
 /// \returns The constructed object writer.
-MCObjectWriter *createWasmObjectWriter(MCWasmObjectTargetWriter *MOTW,
-                                       raw_pwrite_stream &OS);
+MCObjectWriter *
+createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
+                       raw_pwrite_stream &OS);
 
 } // End llvm namespace
 
index af5c1a759c77373edcbeb02b5de146d03347539e..02d8bfbe1de716ab3c98f4024c01c842d8b0a2e4 100644 (file)
@@ -227,8 +227,10 @@ class WasmObjectWriter : public MCObjectWriter {
   void endSection(SectionBookkeeping &Section);
 
 public:
-  WasmObjectWriter(MCWasmObjectTargetWriter *MOTW, raw_pwrite_stream &OS)
-      : MCObjectWriter(OS, /*IsLittleEndian=*/true), TargetObjectWriter(MOTW) {}
+  WasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
+                   raw_pwrite_stream &OS)
+      : MCObjectWriter(OS, /*IsLittleEndian=*/true),
+        TargetObjectWriter(std::move(MOTW)) {}
 
 private:
   ~WasmObjectWriter() override;
@@ -1315,7 +1317,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm,
   // TODO: Translate debug sections to the output.
 }
 
-MCObjectWriter *llvm::createWasmObjectWriter(MCWasmObjectTargetWriter *MOTW,
-                                             raw_pwrite_stream &OS) {
-  return new WasmObjectWriter(MOTW, OS);
+MCObjectWriter *
+llvm::createWasmObjectWriter(std::unique_ptr<MCWasmObjectTargetWriter> MOTW,
+                             raw_pwrite_stream &OS) {
+  return new WasmObjectWriter(std::move(MOTW), OS);
 }
index 995984b0361646194921bca410268abf5acb9695..af973193246996258396f786bdd852939dd0d289 100644 (file)
@@ -95,6 +95,6 @@ WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
 
 MCObjectWriter *llvm::createWebAssemblyWasmObjectWriter(raw_pwrite_stream &OS,
                                                         bool Is64Bit) {
-  MCWasmObjectTargetWriter *MOTW = new WebAssemblyWasmObjectWriter(Is64Bit);
-  return createWasmObjectWriter(MOTW, OS);
+  auto MOTW = llvm::make_unique<WebAssemblyWasmObjectWriter>(Is64Bit);
+  return createWasmObjectWriter(std::move(MOTW), OS);
 }