LTO: Simplify ownership of LTOCodeGenerator::TargetMach.

llvm-svn: 245671
diff --git a/llvm/include/llvm/LTO/LTOCodeGenerator.h b/llvm/include/llvm/LTO/LTOCodeGenerator.h
index 695de5aa..a7ccbce 100644
--- a/llvm/include/llvm/LTO/LTOCodeGenerator.h
+++ b/llvm/include/llvm/LTO/LTOCodeGenerator.h
@@ -159,7 +159,7 @@
   std::unique_ptr<LLVMContext> OwnedContext;
   LLVMContext &Context;
   Linker IRLinker;
-  TargetMachine *TargetMach = nullptr;
+  std::unique_ptr<TargetMachine> TargetMach;
   bool EmitDwarfDebugInfo = false;
   bool ScopeRestrictionsDone = false;
   lto_codegen_model CodeModel = LTO_CODEGEN_PIC_MODEL_DEFAULT;
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index fdf3f3a..6203000 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -86,9 +86,6 @@
 
 LTOCodeGenerator::~LTOCodeGenerator() {
   destroyMergedModule();
-
-  delete TargetMach;
-  TargetMach = nullptr;
 }
 
 // Initialize LTO passes. Please keep this funciton in sync with
@@ -352,9 +349,9 @@
     break;
   }
 
-  TargetMach = march->createTargetMachine(TripleStr, MCpu, FeatureStr, Options,
-                                          RelocModel, CodeModel::Default,
-                                          CGOptLevel);
+  TargetMach.reset(march->createTargetMachine(TripleStr, MCpu, FeatureStr,
+                                              Options, RelocModel,
+                                              CodeModel::Default, CGOptLevel));
   return true;
 }