diff options
author | Nikita Popov <npopov@redhat.com> | 2022-10-11 11:01:29 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-10-11 11:05:21 +0200 |
commit | ac47db6acad29b6e077593430338be69d81cb6c0 (patch) | |
tree | c2d7da6151e4cb0961111d8cf0d7fec2f9477e56 /llvm/lib/IR/Attributes.cpp | |
parent | 256976774f6d41a6f851e5e1dd2da2fddad1377e (diff) | |
download | llvm-ac47db6acad29b6e077593430338be69d81cb6c0.zip llvm-ac47db6acad29b6e077593430338be69d81cb6c0.tar.gz llvm-ac47db6acad29b6e077593430338be69d81cb6c0.tar.bz2 |
[Attributes] Return Optional from getAllocSizeArgs() (NFC)
As suggested on D135572, return Optional<> from getAllocSizeArgs()
rather than the peculiar pair(0, 0) sentinel.
The method on Attribute itself does not return Optional, because
the attribute must exist in that case.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 256d81f..3ae15b6 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -745,9 +745,11 @@ Type *AttributeSet::getElementType() const { return SetNode ? SetNode->getAttributeType(Attribute::ElementType) : nullptr; } -std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const { - return SetNode ? SetNode->getAllocSizeArgs() - : std::pair<unsigned, Optional<unsigned>>(0, 0); +Optional<std::pair<unsigned, Optional<unsigned>>> +AttributeSet::getAllocSizeArgs() const { + if (SetNode) + return SetNode->getAllocSizeArgs(); + return None; } unsigned AttributeSet::getVScaleRangeMin() const { @@ -913,11 +915,11 @@ uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const { return 0; } -std::pair<unsigned, Optional<unsigned>> +Optional<std::pair<unsigned, Optional<unsigned>>> AttributeSetNode::getAllocSizeArgs() const { if (auto A = findEnumAttribute(Attribute::AllocSize)) return A->getAllocSizeArgs(); - return std::make_pair(0, 0); + return None; } unsigned AttributeSetNode::getVScaleRangeMin() const { @@ -1653,8 +1655,12 @@ AttrBuilder &AttrBuilder::addRawIntAttr(Attribute::AttrKind Kind, return addAttribute(Attribute::get(Ctx, Kind, Value)); } -std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const { - return unpackAllocSizeArgs(getRawIntAttr(Attribute::AllocSize).value_or(0)); +Optional<std::pair<unsigned, Optional<unsigned>>> +AttrBuilder::getAllocSizeArgs() const { + Attribute A = getAttribute(Attribute::AllocSize); + if (A.isValid()) + return A.getAllocSizeArgs(); + return None; } AttrBuilder &AttrBuilder::addAlignmentAttr(MaybeAlign Align) { |