Skip to content

Commit 6aebb5d

Browse files
committed
AttributeParser: Convert Optional to std::optional
1 parent 4763e87 commit 6aebb5d

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

llvm/include/llvm/Support/ELFAttributeParser.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/Support/Endian.h"
1616
#include "llvm/Support/Error.h"
1717

18+
#include <optional>
1819
#include <unordered_map>
1920

2021
namespace llvm {
@@ -59,16 +60,16 @@ class ELFAttributeParser {
5960

6061
Error parse(ArrayRef<uint8_t> section, support::endianness endian);
6162

62-
Optional<unsigned> getAttributeValue(unsigned tag) const {
63+
std::optional<unsigned> getAttributeValue(unsigned tag) const {
6364
auto I = attributes.find(tag);
6465
if (I == attributes.end())
65-
return None;
66+
return std::nullopt;
6667
return I->second;
6768
}
68-
Optional<StringRef> getAttributeString(unsigned tag) const {
69+
std::optional<StringRef> getAttributeString(unsigned tag) const {
6970
auto I = attributesStr.find(tag);
7071
if (I == attributesStr.end())
71-
return None;
72+
return std::nullopt;
7273
return I->second;
7374
}
7475
};

llvm/lib/Object/ELFObjectFile.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const {
166166

167167
// both ARMv7-M and R have to support thumb hardware div
168168
bool isV7 = false;
169-
Optional<unsigned> Attr =
169+
std::optional<unsigned> Attr =
170170
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
171171
if (Attr)
172172
isV7 = Attr.value() == ARMBuildAttrs::v7;
@@ -303,7 +303,8 @@ SubtargetFeatures ELFObjectFileBase::getRISCVFeatures() const {
303303
return Features; // Keep "c" feature if there is one in PlatformFlags.
304304
}
305305

306-
Optional<StringRef> Attr = Attributes.getAttributeString(RISCVAttrs::ARCH);
306+
std::optional<StringRef> Attr =
307+
Attributes.getAttributeString(RISCVAttrs::ARCH);
307308
if (Attr) {
308309
// The Arch pattern is [rv32|rv64][i|e]version(_[m|a|f|d|c]version)*
309310
// Version string pattern is (major)p(minor). Major and minor are optional.
@@ -542,7 +543,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
542543
else
543544
Triple = "arm";
544545

545-
Optional<unsigned> Attr =
546+
std::optional<unsigned> Attr =
546547
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
547548
if (Attr) {
548549
switch (Attr.value()) {
@@ -574,7 +575,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
574575
Triple += "v6k";
575576
break;
576577
case ARMBuildAttrs::v7: {
577-
Optional<unsigned> ArchProfileAttr =
578+
std::optional<unsigned> ArchProfileAttr =
578579
Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
579580
if (ArchProfileAttr &&
580581
ArchProfileAttr.value() == ARMBuildAttrs::MicroControllerProfile)

llvm/unittests/Support/ARMAttributeParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool testBuildAttr(unsigned Tag, unsigned Value,
3737
ARMAttributeParser Parser;
3838
cantFail(Parser.parse(Bytes, support::little));
3939

40-
Optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
40+
std::optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
4141
return Attr && *Attr == ExpectedValue;
4242
}
4343

llvm/unittests/Support/CSKYAttributeParserTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static bool testAttributeInt(unsigned Tag, unsigned Value, unsigned ExpectedTag,
8383
CSKYAttributeParser Parser;
8484
cantFail(Parser.parse(Bytes, support::little));
8585

86-
Optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
86+
std::optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
8787
return Attr && *Attr == ExpectedValue;
8888
}
8989

@@ -100,7 +100,7 @@ static bool testAttributeString(unsigned Tag, const char *Value,
100100
CSKYAttributeParser Parser;
101101
cantFail(Parser.parse(Bytes, support::little));
102102

103-
Optional<StringRef> Attr = Parser.getAttributeString(ExpectedTag);
103+
std::optional<StringRef> Attr = Parser.getAttributeString(ExpectedTag);
104104
return Attr && *Attr == ExpectedValue;
105105
}
106106

llvm/unittests/Support/RISCVAttributeParserTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static bool testAttribute(unsigned Tag, unsigned Value, unsigned ExpectedTag,
4444
RISCVAttributeParser Parser;
4545
cantFail(Parser.parse(Bytes, support::little));
4646

47-
Optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
47+
std::optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
4848
return Attr && *Attr == ExpectedValue;
4949
}
5050

0 commit comments

Comments
 (0)