Skip to content

Commit 228e96b

Browse files
[llvm] Use std::make_optional (NFC) (#151627)
std::make_optional<T> is a lot like std::make_unique<T> in that it performs perfect forwarding of arguments for T's constructor. As a result, we don't have to repeat type names twice.
1 parent 666874a commit 228e96b

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6494,7 +6494,7 @@ struct AAAllocationInfo : public StateWrapper<BooleanState, AbstractAttribute> {
64946494
}
64956495

64966496
constexpr static const std::optional<TypeSize> HasNoAllocationSize =
6497-
std::optional<TypeSize>(TypeSize(-1, true));
6497+
std::make_optional<TypeSize>(-1, true);
64986498

64996499
LLVM_ABI static const char ID;
65006500
};

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ DIDerivedType *DIDerivedType::getImpl(
10121012
std::optional<DIDerivedType::PtrAuthData>
10131013
DIDerivedType::getPtrAuthData() const {
10141014
return getTag() == dwarf::DW_TAG_LLVM_ptrauth_type
1015-
? std::optional<PtrAuthData>(PtrAuthData(SubclassData32))
1015+
? std::make_optional<PtrAuthData>(SubclassData32)
10161016
: std::nullopt;
10171017
}
10181018

llvm/lib/Remarks/RemarkLinker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Error RemarkLinker::link(StringRef Buffer, Format RemarkFormat) {
7070
Expected<std::unique_ptr<RemarkParser>> MaybeParser =
7171
createRemarkParserFromMeta(
7272
RemarkFormat, Buffer,
73-
PrependPath ? std::optional<StringRef>(StringRef(*PrependPath))
74-
: std::optional<StringRef>());
73+
PrependPath ? std::make_optional<StringRef>(*PrependPath)
74+
: std::nullopt);
7575
if (!MaybeParser)
7676
return MaybeParser.takeError();
7777

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13404,7 +13404,7 @@ struct AAAllocationInfoImpl : public AAAllocationInfo {
1340413404
return indicatePessimisticFixpoint();
1340513405

1340613406
if (BinSize == 0) {
13407-
auto NewAllocationSize = std::optional<TypeSize>(TypeSize(0, false));
13407+
auto NewAllocationSize = std::make_optional<TypeSize>(0, false);
1340813408
if (!changeAllocationSize(NewAllocationSize))
1340913409
return ChangeStatus::UNCHANGED;
1341013410
return ChangeStatus::CHANGED;
@@ -13422,8 +13422,7 @@ struct AAAllocationInfoImpl : public AAAllocationInfo {
1342213422
if (SizeOfBin >= *AllocationSize)
1342313423
return indicatePessimisticFixpoint();
1342413424

13425-
auto NewAllocationSize =
13426-
std::optional<TypeSize>(TypeSize(SizeOfBin * 8, false));
13425+
auto NewAllocationSize = std::make_optional<TypeSize>(SizeOfBin * 8, false);
1342713426

1342813427
if (!changeAllocationSize(NewAllocationSize))
1342913428
return ChangeStatus::UNCHANGED;

0 commit comments

Comments
 (0)