[llvm] [LIB][TOOLS] Modernize unique_ptr new() C++11 to std::make_unique C++17 (PR #124690)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 20:02:52 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-objectyaml

Author: Herman Semenoff (GermanAizek)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/124690.diff


27 Files Affected:

- (modified) llvm/include/llvm/BinaryFormat/MsgPackDocument.h (+1-1) 
- (modified) llvm/include/llvm/CodeGen/RegAllocPBQP.h (+1-1) 
- (modified) llvm/include/llvm/Transforms/Scalar/LoopPassManager.h (+2-6) 
- (modified) llvm/lib/CodeGen/DetectDeadLanes.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp (+1-2) 
- (modified) llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp (+1-1) 
- (modified) llvm/lib/DebugInfo/PDB/Native/NativeTypeFunctionSig.cpp (+1-2) 
- (modified) llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp (+1-2) 
- (modified) llvm/lib/InterfaceStub/IFSHandler.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOBackend.cpp (+1-2) 
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+1-2) 
- (modified) llvm/lib/MC/MCDisassembler/Disassembler.cpp (+2-2) 
- (modified) llvm/lib/Object/GOFFObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Object/MachOUniversal.cpp (+1-2) 
- (modified) llvm/lib/Object/SymbolicFile.cpp (+1-1) 
- (modified) llvm/lib/Object/TapiUniversal.cpp (+1-1) 
- (modified) llvm/lib/Support/VirtualFileSystem.cpp (+1-2) 
- (modified) llvm/lib/Target/SPIRV/SPIRVAPI.cpp (+1-2) 
- (modified) llvm/lib/TextAPI/InterfaceFile.cpp (+1-1) 
- (modified) llvm/tools/llvm-as/llvm-as.cpp (+1-2) 
- (modified) llvm/tools/llvm-dis/llvm-dis.cpp (+2-2) 
- (modified) llvm/tools/llvm-link/llvm-link.cpp (+1-1) 
- (modified) llvm/tools/llvm-modextract/llvm-modextract.cpp (+1-2) 
- (modified) llvm/tools/llvm-sim/llvm-sim.cpp (+1-2) 
- (modified) llvm/tools/llvm-split/llvm-split.cpp (+1-2) 
- (modified) llvm/tools/obj2yaml/obj2yaml.cpp (+1-2) 
- (modified) llvm/tools/yaml2obj/yaml2obj.cpp (+1-2) 


``````````diff
diff --git a/llvm/include/llvm/BinaryFormat/MsgPackDocument.h b/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
index 09091264cac2d2..183d055ff2b816 100644
--- a/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
+++ b/llvm/include/llvm/BinaryFormat/MsgPackDocument.h
@@ -437,7 +437,7 @@ class Document {
   /// Copy a string into the Document's strings list, and return the copy that
   /// is owned by the Document.
   StringRef addString(StringRef S) {
-    Strings.push_back(std::unique_ptr<char[]>(new char[S.size()]));
+    Strings.push_back(std::make_unique<char[]>(S.size()));
     memcpy(&Strings.back()[0], S.data(), S.size());
     return StringRef(&Strings.back()[0], S.size());
   }
diff --git a/llvm/include/llvm/CodeGen/RegAllocPBQP.h b/llvm/include/llvm/CodeGen/RegAllocPBQP.h
index 234f1c6ff115ac..7bd8216c79c0ef 100644
--- a/llvm/include/llvm/CodeGen/RegAllocPBQP.h
+++ b/llvm/include/llvm/CodeGen/RegAllocPBQP.h
@@ -210,7 +210,7 @@ class NodeMetadata {
 
   void setup(const Vector& Costs) {
     NumOpts = Costs.getLength() - 1;
-    OptUnsafeEdges = std::unique_ptr<unsigned[]>(new unsigned[NumOpts]());
+    OptUnsafeEdges = std::make_unique<unsigned[]>(NumOpts);
   }
 
   ReductionState getReductionState() const { return RS; }
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index f55022fbff07c1..39c6c8ab48335c 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -474,9 +474,7 @@ createFunctionToLoopPassAdaptor(LoopNestPassT &&Pass, bool UseMemorySSA = false,
                         LoopStandardAnalysisResults &, LPMUpdater &>;
   // Do not use make_unique, it causes too many template instantiations,
   // causing terrible compile times.
-  return FunctionToLoopPassAdaptor(
-      std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
-          new PassModelT(std::move(LPM))),
+  return FunctionToLoopPassAdaptor(std::make_unique<PassModelT>(std::move(LPM)),
       UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo, true);
 }
 
@@ -495,9 +493,7 @@ createFunctionToLoopPassAdaptor<LoopPassManager>(
   bool LoopNestMode = (LPM.getNumLoopPasses() == 0);
   // Do not use make_unique, it causes too many template instantiations,
   // causing terrible compile times.
-  return FunctionToLoopPassAdaptor(
-      std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
-          new PassModelT(std::move(LPM))),
+  return FunctionToLoopPassAdaptor(std::make_unique<PassModelT>(std::move(LPM)),
       UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
       LoopNestMode);
 }
diff --git a/llvm/lib/CodeGen/DetectDeadLanes.cpp b/llvm/lib/CodeGen/DetectDeadLanes.cpp
index 86e9f3abe010d7..549a8db8a1b2d4 100644
--- a/llvm/lib/CodeGen/DetectDeadLanes.cpp
+++ b/llvm/lib/CodeGen/DetectDeadLanes.cpp
@@ -42,7 +42,7 @@ DeadLaneDetector::DeadLaneDetector(const MachineRegisterInfo *MRI,
                                    const TargetRegisterInfo *TRI)
     : MRI(MRI), TRI(TRI) {
   unsigned NumVirtRegs = MRI->getNumVirtRegs();
-  VRegInfos = std::unique_ptr<VRegInfo[]>(new VRegInfo[NumVirtRegs]);
+  VRegInfos = std::make_unique<VRegInfo[]>(NumVirtRegs);
   WorklistMembers.resize(NumVirtRegs);
   DefinedByCopy.resize(NumVirtRegs);
 }
diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
index f1fec547ebd60f..3c808cc8f4a5ce 100644
--- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
@@ -215,8 +215,7 @@ bool RegBankSelect::repairReg(
   // TODO:
   // Check if MI is legal. if not, we need to legalize all the
   // instructions we are going to insert.
-  std::unique_ptr<MachineInstr *[]> NewInstrs(
-      new MachineInstr *[RepairPt.getNumInsertPoints()]);
+  auto NewInstrs = std::make_unique<MachineInstr *[]>(RepairPt.getNumInsertPoints());
   bool IsFirst = true;
   unsigned Idx = 0;
   for (const std::unique_ptr<InsertPoint> &InsertPt : RepairPt) {
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
index 8571ca632f52bd..6d2d73e1752615 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeExeSymbol.cpp
@@ -36,7 +36,7 @@ std::unique_ptr<IPDBEnumSymbols>
 NativeExeSymbol::findChildren(PDB_SymType Type) const {
   switch (Type) {
   case PDB_SymType::Compiland: {
-    return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
+    return std::make_unique<NativeEnumModules>(Session);
     break;
   }
   case PDB_SymType::ArrayType:
diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeTypeFunctionSig.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeTypeFunctionSig.cpp
index 7db3f1c6312887..4819409640a380 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeTypeFunctionSig.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeTypeFunctionSig.cpp
@@ -138,8 +138,7 @@ NativeTypeFunctionSig::findChildren(PDB_SymType Type) const {
 
   auto NET = std::make_unique<NativeEnumTypes>(Session,
                                                 /* copy */ ArgList.ArgIndices);
-  return std::unique_ptr<IPDBEnumSymbols>(
-      new NativeEnumFunctionArgs(Session, std::move(NET)));
+  return std::make_unique<NativeEnumFunctionArgs>(Session, std::move(NET));
 }
 
 SymIndexId NativeTypeFunctionSig::getClassParentId() const {
diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
index 95b95a5bbc509f..e531b8adea60d7 100644
--- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
@@ -98,8 +98,7 @@ SymbolCache::createTypeEnumerator(std::vector<TypeLeafKind> Kinds) {
     return nullptr;
   }
   auto &Types = Tpi->typeCollection();
-  return std::unique_ptr<IPDBEnumSymbols>(
-      new NativeEnumTypes(Session, Types, std::move(Kinds)));
+  return std::make_unique<NativeEnumTypes>(Session, Types, std::move(Kinds));
 }
 
 std::unique_ptr<IPDBEnumSymbols>
diff --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp
index e80a59a572d888..6ff406980d5569 100644
--- a/llvm/lib/InterfaceStub/IFSHandler.cpp
+++ b/llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -178,7 +178,7 @@ bool usesTriple(StringRef Buf) {
 
 Expected<std::unique_ptr<IFSStub>> ifs::readIFSFromBuffer(StringRef Buf) {
   yaml::Input YamlIn(Buf);
-  std::unique_ptr<IFSStubTriple> Stub(new IFSStubTriple());
+  auto Stub = std::make_unique<IFSStubTriple>();
   if (usesTriple(Buf)) {
     YamlIn >> *Stub;
   } else {
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 8a2dddce4892c1..aa85e6b0964241 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -275,8 +275,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
 
   RegisterPassPlugins(Conf.PassPlugins, PB);
 
-  std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
+  auto TLII = std::make_unique<TargetLibraryInfoImpl> (Triple(TM->getTargetTriple()));
   if (Conf.Freestanding)
     TLII->disableAllFunctions();
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 189f2876b61c0f..9821594a08994a 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -251,8 +251,7 @@ static void optimizeModule(Module &TheModule, TargetMachine &TM,
   PTO.SLPVectorization = true;
   PassBuilder PB(&TM, PTO, PGOOpt, &PIC);
 
-  std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(Triple(TM.getTargetTriple())));
+  auto TLII = std::make_unique<TargetLibraryInfoImpl>(Triple(TM.getTargetTriple()));
   if (Freestanding)
     TLII->disableAllFunctions();
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
diff --git a/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
index 684413e1e3a537..f9b13a6d8bc83c 100644
--- a/llvm/lib/MC/MCDisassembler/Disassembler.cpp
+++ b/llvm/lib/MC/MCDisassembler/Disassembler.cpp
@@ -72,8 +72,8 @@ LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU,
     return nullptr;
 
   // Set up the MCContext for creating symbols and MCExpr's.
-  std::unique_ptr<MCContext> Ctx(
-      new MCContext(Triple(TT), MAI.get(), MRI.get(), STI.get()));
+  auto Ctx = std::make_unique<MCContext>(
+      Triple(TT), MAI.get(), MRI.get(), STI.get());
   if (!Ctx)
     return nullptr;
 
diff --git a/llvm/lib/Object/GOFFObjectFile.cpp b/llvm/lib/Object/GOFFObjectFile.cpp
index db1e7e704f62e1..02f09525465aa3 100644
--- a/llvm/lib/Object/GOFFObjectFile.cpp
+++ b/llvm/lib/Object/GOFFObjectFile.cpp
@@ -27,7 +27,7 @@ using namespace llvm;
 Expected<std::unique_ptr<ObjectFile>>
 ObjectFile::createGOFFObjectFile(MemoryBufferRef Object) {
   Error Err = Error::success();
-  std::unique_ptr<GOFFObjectFile> Ret(new GOFFObjectFile(Object, Err));
+  auto Ret = std::make_unique<GOFFObjectFile>(Object, Err);
   if (Err)
     return std::move(Err);
   return std::move(Ret);
diff --git a/llvm/lib/Object/MachOUniversal.cpp b/llvm/lib/Object/MachOUniversal.cpp
index 31bb2a619ff334..0094d4b2fa8f0b 100644
--- a/llvm/lib/Object/MachOUniversal.cpp
+++ b/llvm/lib/Object/MachOUniversal.cpp
@@ -121,8 +121,7 @@ void MachOUniversalBinary::anchor() { }
 Expected<std::unique_ptr<MachOUniversalBinary>>
 MachOUniversalBinary::create(MemoryBufferRef Source) {
   Error Err = Error::success();
-  std::unique_ptr<MachOUniversalBinary> Ret(
-      new MachOUniversalBinary(Source, Err));
+  auto Ret = std::make_unique<MachOUniversalBinary>(Source, Err);
   if (Err)
     return std::move(Err);
   return std::move(Ret);
diff --git a/llvm/lib/Object/SymbolicFile.cpp b/llvm/lib/Object/SymbolicFile.cpp
index e87ecb14910904..49f94391ec2f33 100644
--- a/llvm/lib/Object/SymbolicFile.cpp
+++ b/llvm/lib/Object/SymbolicFile.cpp
@@ -70,7 +70,7 @@ SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type,
   case file_magic::wasm_object:
     return ObjectFile::createObjectFile(Object, Type, InitContent);
   case file_magic::coff_import_library:
-    return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
+    return std::make_unique<COFFImportFile>(Object);
   case file_magic::elf_relocatable:
   case file_magic::macho_object:
   case file_magic::coff_object: {
diff --git a/llvm/lib/Object/TapiUniversal.cpp b/llvm/lib/Object/TapiUniversal.cpp
index 74e0c519ddfdb5..3614a57caaf668 100644
--- a/llvm/lib/Object/TapiUniversal.cpp
+++ b/llvm/lib/Object/TapiUniversal.cpp
@@ -53,7 +53,7 @@ TapiUniversal::ObjectForArch::getAsObjectFile() const {
 Expected<std::unique_ptr<TapiUniversal>>
 TapiUniversal::create(MemoryBufferRef Source) {
   Error Err = Error::success();
-  std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));
+  auto Ret = std::make_unique<TapiUniversal>(Source, Err);
   if (Err)
     return std::move(Err);
   return std::move(Ret);
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index e489282281d269..785141b4d505d4 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -1093,8 +1093,7 @@ InMemoryFileSystem::openFileForRead(const Twine &Path) {
   // When we have a file provide a heap-allocated wrapper for the memory buffer
   // to match the ownership semantics for File.
   if (auto *F = dyn_cast<detail::InMemoryFile>(*Node))
-    return std::unique_ptr<File>(
-        new detail::InMemoryFileAdaptor(*F, Path.str()));
+    return std::make_unique<detail::InMemoryFileAdaptor>(*F, Path.str());
 
   // FIXME: errc::not_a_file?
   return make_error_code(llvm::errc::invalid_argument);
diff --git a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
index 95c9b0e5200608..8fbe445a663ec2 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAPI.cpp
@@ -158,8 +158,7 @@ SPIRVTranslateModule(Module *M, std::string &SpirvObj, std::string &ErrMsg,
   TargetLibraryInfoImpl TLII(Triple(M->getTargetTriple()));
   legacy::PassManager PM;
   PM.add(new TargetLibraryInfoWrapperPass(TLII));
-  std::unique_ptr<MachineModuleInfoWrapperPass> MMIWP(
-      new MachineModuleInfoWrapperPass(Target.get()));
+  auto MMIWP = std::make_unique<MachineModuleInfoWrapperPass>(Target.get());
   const_cast<TargetLoweringObjectFile *>(Target->getObjFileLowering())
       ->Initialize(MMIWP.get()->getMMI().getContext(), *Target);
 
diff --git a/llvm/lib/TextAPI/InterfaceFile.cpp b/llvm/lib/TextAPI/InterfaceFile.cpp
index ce2feb65c9ec9d..0e4980fc0bc8e9 100644
--- a/llvm/lib/TextAPI/InterfaceFile.cpp
+++ b/llvm/lib/TextAPI/InterfaceFile.cpp
@@ -310,7 +310,7 @@ InterfaceFile::extract(Architecture Arch) const {
                                    inconvertibleErrorCode());
   }
 
-  std::unique_ptr<InterfaceFile> IF(new InterfaceFile());
+  auto IF = std::make_unique<InterfaceFile>();
   IF->setFileType(getFileType());
   IF->setPath(getPath());
   IF->addTargets(targets(Arch));
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
index d8e36de59bcb4f..4615c76ba6aa15 100644
--- a/llvm/tools/llvm-as/llvm-as.cpp
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -82,8 +82,7 @@ static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) {
   }
 
   std::error_code EC;
-  std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+  auto Out = std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_None);
   if (EC) {
     errs() << EC.message() << '\n';
     exit(1);
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 49acc9cd456ff4..40c71868b39ed1 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -262,8 +262,8 @@ int main(int argc, char **argv) {
       }
 
       std::error_code EC;
-      std::unique_ptr<ToolOutputFile> Out(
-          new ToolOutputFile(FinalFilename, EC, sys::fs::OF_TextWithCRLF));
+      auto Out = std::make_unique<ToolOutputFile>(
+        FinalFilename, EC, sys::fs::OF_TextWithCRLF);
       if (EC) {
         errs() << EC.message() << '\n';
         return 1;
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 0f4a4d57427a57..95623a457b03a6 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -176,7 +176,7 @@ static std::unique_ptr<Module> loadFile(const char *argv0,
 static std::unique_ptr<Module> loadArFile(const char *Argv0,
                                           std::unique_ptr<MemoryBuffer> Buffer,
                                           LLVMContext &Context) {
-  std::unique_ptr<Module> Result(new Module("ArchiveModule", Context));
+  auto Result = std::make_unique<Module>("ArchiveModule", Context);
   StringRef ArchiveName = Buffer->getBufferIdentifier();
   if (Verbose)
     errs() << "Reading library archive file '" << ArchiveName
diff --git a/llvm/tools/llvm-modextract/llvm-modextract.cpp b/llvm/tools/llvm-modextract/llvm-modextract.cpp
index 50f503ae0ac4c6..384260a26716dc 100644
--- a/llvm/tools/llvm-modextract/llvm-modextract.cpp
+++ b/llvm/tools/llvm-modextract/llvm-modextract.cpp
@@ -63,8 +63,7 @@ int main(int argc, char **argv) {
   }
 
   std::error_code EC;
-  std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+  auto Out = std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_None);
   ExitOnErr(errorCodeToError(EC));
 
   if (BinaryExtract) {
diff --git a/llvm/tools/llvm-sim/llvm-sim.cpp b/llvm/tools/llvm-sim/llvm-sim.cpp
index d09e51561253a7..abd95918244015 100644
--- a/llvm/tools/llvm-sim/llvm-sim.cpp
+++ b/llvm/tools/llvm-sim/llvm-sim.cpp
@@ -63,8 +63,7 @@ exportToFile(const StringRef FilePath,
              const SimilarityGroupList &SimSections,
              const DenseMap<Instruction *, unsigned> &LLVMInstNum) {
   std::error_code EC;
-  std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(FilePath, EC, sys::fs::OF_None));
+  auto Out = std::make_unique<ToolOutputFile>(FilePath, EC, sys::fs::OF_None);
   if (EC)
     return EC;
 
diff --git a/llvm/tools/llvm-split/llvm-split.cpp b/llvm/tools/llvm-split/llvm-split.cpp
index 1b1f97f44e2742..4d46e2f0521b4e 100644
--- a/llvm/tools/llvm-split/llvm-split.cpp
+++ b/llvm/tools/llvm-split/llvm-split.cpp
@@ -105,8 +105,7 @@ int main(int argc, char **argv) {
   unsigned I = 0;
   const auto HandleModulePart = [&](std::unique_ptr<Module> MPart) {
     std::error_code EC;
-    std::unique_ptr<ToolOutputFile> Out(
-        new ToolOutputFile(OutputFilename + utostr(I++), EC, sys::fs::OF_None));
+    auto Out = std::make_unique<ToolOutputFile>(OutputFilename + utostr(I++), EC, sys::fs::OF_None);
     if (EC) {
       errs() << EC.message() << '\n';
       exit(1);
diff --git a/llvm/tools/obj2yaml/obj2yaml.cpp b/llvm/tools/obj2yaml/obj2yaml.cpp
index 63c8cc55ee2d4a..4168160e28e2e1 100644
--- a/llvm/tools/obj2yaml/obj2yaml.cpp
+++ b/llvm/tools/obj2yaml/obj2yaml.cpp
@@ -107,8 +107,7 @@ int main(int argc, char *argv[]) {
       nullptr, /*LongOptionsUseDoubleDash=*/true);
 
   std::error_code EC;
-  std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_Text));
+  auto Out = std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_Text);
   if (EC) {
     WithColor::error(errs(), "obj2yaml")
         << "failed to open '" + OutputFilename + "': " + EC.message() << '\n';
diff --git a/llvm/tools/yaml2obj/yaml2obj.cpp b/llvm/tools/yaml2obj/yaml2obj.cpp
index 4a060e1aad427f..39aff22dc6e8f7 100644
--- a/llvm/tools/yaml2obj/yaml2obj.cpp
+++ b/llvm/tools/yaml2obj/yaml2obj.cpp
@@ -122,8 +122,7 @@ int main(int argc, char **argv) {
   };
 
   std::error_code EC;
-  std::unique_ptr<ToolOutputFile> Out(
-      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_None));
+  auto Out = std::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::OF_None);
   if (EC) {
     ErrHandler("failed to open '" + OutputFilename + "': " + EC.message());
     return 1;

``````````

</details>


https://github.com/llvm/llvm-project/pull/124690


More information about the llvm-commits mailing list