Skip to content

Commit ddaa93b

Browse files
[llvm] Use std::make_unique (NFC) (#97165)
This patch is based on clang-tidy's modernize-make-unique but limited to those cases where type names are mentioned twice like std::unique_ptr<Type>(new Type()), which is a bit mouthful.
1 parent 9cdc853 commit ddaa93b

File tree

11 files changed

+17
-22
lines changed

11 files changed

+17
-22
lines changed

llvm/include/llvm/BinaryFormat/MsgPackDocument.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ class Document {
388388
/// Create an empty Map node associated with this Document.
389389
MapDocNode getMapNode() {
390390
auto N = DocNode(&KindAndDocs[size_t(Type::Map)]);
391-
Maps.push_back(std::unique_ptr<DocNode::MapTy>(new DocNode::MapTy));
391+
Maps.push_back(std::make_unique<DocNode::MapTy>());
392392
N.Map = Maps.back().get();
393393
return N.getMap();
394394
}
395395

396396
/// Create an empty Array node associated with this Document.
397397
ArrayDocNode getArrayNode() {
398398
auto N = DocNode(&KindAndDocs[size_t(Type::Array)]);
399-
Arrays.push_back(std::unique_ptr<DocNode::ArrayTy>(new DocNode::ArrayTy));
399+
Arrays.push_back(std::make_unique<DocNode::ArrayTy>());
400400
N.Array = Arrays.back().get();
401401
return N.getArray();
402402
}

llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ SymbolCache::getSourceFileById(SymIndexId FileId) const {
618618
if (FileId == 0)
619619
return nullptr;
620620

621-
return std::unique_ptr<NativeSourceFile>(
622-
new NativeSourceFile(*SourceFiles[FileId].get()));
621+
return std::make_unique<NativeSourceFile>(*SourceFiles[FileId].get());
623622
}
624623

625624
SymIndexId

llvm/lib/ExecutionEngine/Orc/Layer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,8 @@ BasicObjectLayerMaterializationUnit::Create(ObjectLayer &L,
200200
if (!ObjInterface)
201201
return ObjInterface.takeError();
202202

203-
return std::unique_ptr<BasicObjectLayerMaterializationUnit>(
204-
new BasicObjectLayerMaterializationUnit(L, std::move(O),
205-
std::move(*ObjInterface)));
203+
return std::make_unique<BasicObjectLayerMaterializationUnit>(
204+
L, std::move(O), std::move(*ObjInterface));
206205
}
207206

208207
BasicObjectLayerMaterializationUnit::BasicObjectLayerMaterializationUnit(

llvm/lib/Object/TapiUniversal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ TapiUniversal::~TapiUniversal() = default;
4747

4848
Expected<std::unique_ptr<TapiFile>>
4949
TapiUniversal::ObjectForArch::getAsObjectFile() const {
50-
return std::unique_ptr<TapiFile>(new TapiFile(Parent->getMemoryBufferRef(),
51-
*Parent->ParsedFile,
52-
Parent->Libraries[Index].Arch));
50+
return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),
51+
*Parent->ParsedFile,
52+
Parent->Libraries[Index].Arch);
5353
}
5454

5555
Expected<std::unique_ptr<TapiUniversal>>

llvm/lib/Target/ARM/ARMBlockPlacement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ bool ARMBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
219219
LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Running on " << MF.getName() << "\n");
220220
MLI = &getAnalysis<MachineLoopInfo>();
221221
TII = static_cast<const ARMBaseInstrInfo *>(ST.getInstrInfo());
222-
BBUtils = std::unique_ptr<ARMBasicBlockUtils>(new ARMBasicBlockUtils(MF));
222+
BBUtils = std::make_unique<ARMBasicBlockUtils>(MF);
223223
MF.RenumberBlocks();
224224
BBUtils->computeAllBlockSizes();
225225
BBUtils->adjustBBOffsetsAfter(&MF.front());

llvm/lib/Target/ARM/ARMConstantIslandPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static bool AlignBlocks(MachineFunction *MF, const ARMSubtarget *STI) {
388388
bool ARMConstantIslands::runOnMachineFunction(MachineFunction &mf) {
389389
MF = &mf;
390390
MCP = mf.getConstantPool();
391-
BBUtils = std::unique_ptr<ARMBasicBlockUtils>(new ARMBasicBlockUtils(mf));
391+
BBUtils = std::make_unique<ARMBasicBlockUtils>(mf);
392392

393393
LLVM_DEBUG(dbgs() << "***** ARMConstantIslands: "
394394
<< MCP->getConstants().size() << " CP entries, aligned to "

llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ bool ARMLowOverheadLoops::runOnMachineFunction(MachineFunction &mf) {
13011301
MRI = &MF->getRegInfo();
13021302
TII = static_cast<const ARMBaseInstrInfo*>(ST.getInstrInfo());
13031303
TRI = ST.getRegisterInfo();
1304-
BBUtils = std::unique_ptr<ARMBasicBlockUtils>(new ARMBasicBlockUtils(*MF));
1304+
BBUtils = std::make_unique<ARMBasicBlockUtils>(*MF);
13051305
BBUtils->computeAllBlockSizes();
13061306
BBUtils->adjustBBOffsetsAfter(&MF->front());
13071307

llvm/lib/XRay/Profile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Profile mergeProfilesByThread(const Profile &L, const Profile &R) {
202202
for (const auto &Block : P.get()) {
203203
ThreadProfileIndexMap::iterator It;
204204
std::tie(It, std::ignore) = ThreadProfileIndex.insert(
205-
{Block.Thread, PathDataMapPtr{new PathDataMap()}});
205+
{Block.Thread, std::make_unique<PathDataMap>()});
206206
for (const auto &PathAndData : Block.PathData) {
207207
auto &PathID = PathAndData.first;
208208
auto &Data = PathAndData.second;

llvm/tools/lli/ForwardingMemoryManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class RemoteResolver : public LegacyJITSymbolResolver {
9898
auto H = DylibMgr->open("", 0);
9999
if (!H)
100100
return H.takeError();
101-
return std::unique_ptr<RemoteResolver>(
102-
new RemoteResolver(std::move(*DylibMgr), std::move(*H)));
101+
return std::make_unique<RemoteResolver>(std::move(*DylibMgr),
102+
std::move(*H));
103103
}
104104

105105
JITSymbol findSymbol(const std::string &Name) override {

llvm/tools/sancov/sancov.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ RawCoverage::read(const std::string &FileName) {
262262
// to compactify the data.
263263
Addrs->erase(0);
264264

265-
return std::unique_ptr<RawCoverage>(new RawCoverage(std::move(Addrs)));
265+
return std::make_unique<RawCoverage>(std::move(Addrs));
266266
}
267267

268268
// Print coverage addresses.
@@ -460,8 +460,7 @@ static std::unique_ptr<symbolize::LLVMSymbolizer> createSymbolizer() {
460460
symbolize::LLVMSymbolizer::Options SymbolizerOptions;
461461
SymbolizerOptions.Demangle = ClDemangle;
462462
SymbolizerOptions.UseSymbolTable = true;
463-
return std::unique_ptr<symbolize::LLVMSymbolizer>(
464-
new symbolize::LLVMSymbolizer(SymbolizerOptions));
463+
return std::make_unique<symbolize::LLVMSymbolizer>(SymbolizerOptions);
465464
}
466465

467466
static std::string normalizeFilename(const std::string &FileName) {

llvm/unittests/Support/ErrorOrTest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ TEST(ErrorOr, SimpleValue) {
3636
#endif
3737
}
3838

39-
ErrorOr<std::unique_ptr<int> > t3() {
40-
return std::unique_ptr<int>(new int(3));
41-
}
39+
ErrorOr<std::unique_ptr<int>> t3() { return std::make_unique<int>(3); }
4240

4341
TEST(ErrorOr, Types) {
4442
int x;

0 commit comments

Comments
 (0)