From e93170912232b0c4896060d25b8e541a38ce75b9 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 31 Jul 2025 13:48:00 -0700 Subject: [PATCH] [llvm] Use std::make_optional (NFC) std::make_optional is a lot like std::make_unique in that it performs perfect forwarding of arguments for T's constructor. As a result, we don't have to repeat type names twice. --- llvm/include/llvm/Transforms/IPO/Attributor.h | 2 +- llvm/lib/IR/DebugInfoMetadata.cpp | 2 +- llvm/lib/Remarks/RemarkLinker.cpp | 4 ++-- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 5 ++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index 719c0ee136236..e57032a6c5b3c 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -6494,7 +6494,7 @@ struct AAAllocationInfo : public StateWrapper { } constexpr static const std::optional HasNoAllocationSize = - std::optional(TypeSize(-1, true)); + std::make_optional(-1, true); LLVM_ABI static const char ID; }; diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index f16963dce56e1..f1d4549ba015b 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -1012,7 +1012,7 @@ DIDerivedType *DIDerivedType::getImpl( std::optional DIDerivedType::getPtrAuthData() const { return getTag() == dwarf::DW_TAG_LLVM_ptrauth_type - ? std::optional(PtrAuthData(SubclassData32)) + ? std::make_optional(SubclassData32) : std::nullopt; } diff --git a/llvm/lib/Remarks/RemarkLinker.cpp b/llvm/lib/Remarks/RemarkLinker.cpp index 0ca6217edfddd..b00419bd4e51b 100644 --- a/llvm/lib/Remarks/RemarkLinker.cpp +++ b/llvm/lib/Remarks/RemarkLinker.cpp @@ -70,8 +70,8 @@ Error RemarkLinker::link(StringRef Buffer, Format RemarkFormat) { Expected> MaybeParser = createRemarkParserFromMeta( RemarkFormat, Buffer, - PrependPath ? std::optional(StringRef(*PrependPath)) - : std::optional()); + PrependPath ? std::make_optional(*PrependPath) + : std::nullopt); if (!MaybeParser) return MaybeParser.takeError(); diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 3c24d2eca647d..01da01239382b 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -13404,7 +13404,7 @@ struct AAAllocationInfoImpl : public AAAllocationInfo { return indicatePessimisticFixpoint(); if (BinSize == 0) { - auto NewAllocationSize = std::optional(TypeSize(0, false)); + auto NewAllocationSize = std::make_optional(0, false); if (!changeAllocationSize(NewAllocationSize)) return ChangeStatus::UNCHANGED; return ChangeStatus::CHANGED; @@ -13422,8 +13422,7 @@ struct AAAllocationInfoImpl : public AAAllocationInfo { if (SizeOfBin >= *AllocationSize) return indicatePessimisticFixpoint(); - auto NewAllocationSize = - std::optional(TypeSize(SizeOfBin * 8, false)); + auto NewAllocationSize = std::make_optional(SizeOfBin * 8, false); if (!changeAllocationSize(NewAllocationSize)) return ChangeStatus::UNCHANGED;