[llvm] [SandboxIR] Use std::make_unique (NFC) (PR #119824)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 22:41:35 PST 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/119824

With std::make_unique, we don't have to mention the type twice.

Identified with modernize-make-unique.


>From 8cfca52d8a81816cbf4ae68b2fd215360635d4cd Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 12 Dec 2024 22:31:11 -0800
Subject: [PATCH] [SandboxIR] Use std::make_unique (NFC)

With std::make_unique, we don't have to mention the type twice.

Identified with modernize-make-unique.
---
 llvm/lib/SandboxIR/Context.cpp | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/SandboxIR/Context.cpp b/llvm/lib/SandboxIR/Context.cpp
index b86ed5864c1ac1..21efa1091c7ebf 100644
--- a/llvm/lib/SandboxIR/Context.cpp
+++ b/llvm/lib/SandboxIR/Context.cpp
@@ -295,20 +295,17 @@ Value *Context::getOrCreateValueInternal(llvm::Value *LLVMV, llvm::User *U) {
   }
   case llvm::Instruction::CatchSwitch: {
     auto *LLVMCatchSwitchInst = cast<llvm::CatchSwitchInst>(LLVMV);
-    It->second = std::unique_ptr<CatchSwitchInst>(
-        new CatchSwitchInst(LLVMCatchSwitchInst, *this));
+    It->second = std::make_unique<CatchSwitchInst>(LLVMCatchSwitchInst, *this);
     return It->second.get();
   }
   case llvm::Instruction::Resume: {
     auto *LLVMResumeInst = cast<llvm::ResumeInst>(LLVMV);
-    It->second =
-        std::unique_ptr<ResumeInst>(new ResumeInst(LLVMResumeInst, *this));
+    It->second = std::make_unique<ResumeInst>(LLVMResumeInst, *this);
     return It->second.get();
   }
   case llvm::Instruction::Switch: {
     auto *LLVMSwitchInst = cast<llvm::SwitchInst>(LLVMV);
-    It->second =
-        std::unique_ptr<SwitchInst>(new SwitchInst(LLVMSwitchInst, *this));
+    It->second = std::make_unique<SwitchInst>(LLVMSwitchInst, *this);
     return It->second.get();
   }
   case llvm::Instruction::FNeg: {
@@ -549,15 +546,15 @@ Context::createGetElementPtrInst(llvm::GetElementPtrInst *I) {
   return cast<GetElementPtrInst>(registerValue(std::move(NewPtr)));
 }
 CatchSwitchInst *Context::createCatchSwitchInst(llvm::CatchSwitchInst *I) {
-  auto NewPtr = std::unique_ptr<CatchSwitchInst>(new CatchSwitchInst(I, *this));
+  auto NewPtr = std::make_unique<CatchSwitchInst>(I, *this);
   return cast<CatchSwitchInst>(registerValue(std::move(NewPtr)));
 }
 ResumeInst *Context::createResumeInst(llvm::ResumeInst *I) {
-  auto NewPtr = std::unique_ptr<ResumeInst>(new ResumeInst(I, *this));
+  auto NewPtr = std::make_unique<ResumeInst>(I, *this);
   return cast<ResumeInst>(registerValue(std::move(NewPtr)));
 }
 SwitchInst *Context::createSwitchInst(llvm::SwitchInst *I) {
-  auto NewPtr = std::unique_ptr<SwitchInst>(new SwitchInst(I, *this));
+  auto NewPtr = std::make_unique<SwitchInst>(I, *this);
   return cast<SwitchInst>(registerValue(std::move(NewPtr)));
 }
 UnaryOperator *Context::createUnaryOperator(llvm::UnaryOperator *I) {



More information about the llvm-commits mailing list