From 6aebb5d17765c1f9946d2281c9f697328799cde4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 2 Dec 2022 07:43:18 +0000 Subject: [PATCH] AttributeParser: Convert Optional to std::optional --- llvm/include/llvm/Support/ELFAttributeParser.h | 9 +++++---- llvm/lib/Object/ELFObjectFile.cpp | 9 +++++---- llvm/unittests/Support/ARMAttributeParser.cpp | 2 +- llvm/unittests/Support/CSKYAttributeParserTest.cpp | 4 ++-- llvm/unittests/Support/RISCVAttributeParserTest.cpp | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/Support/ELFAttributeParser.h b/llvm/include/llvm/Support/ELFAttributeParser.h index 89a1acc..75ed82b 100644 --- a/llvm/include/llvm/Support/ELFAttributeParser.h +++ b/llvm/include/llvm/Support/ELFAttributeParser.h @@ -15,6 +15,7 @@ #include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" +#include #include namespace llvm { @@ -59,16 +60,16 @@ public: Error parse(ArrayRef section, support::endianness endian); - Optional getAttributeValue(unsigned tag) const { + std::optional getAttributeValue(unsigned tag) const { auto I = attributes.find(tag); if (I == attributes.end()) - return None; + return std::nullopt; return I->second; } - Optional getAttributeString(unsigned tag) const { + std::optional getAttributeString(unsigned tag) const { auto I = attributesStr.find(tag); if (I == attributesStr.end()) - return None; + return std::nullopt; return I->second; } }; diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index 5726299..31f0090 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -166,7 +166,7 @@ SubtargetFeatures ELFObjectFileBase::getARMFeatures() const { // both ARMv7-M and R have to support thumb hardware div bool isV7 = false; - Optional Attr = + std::optional Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch); if (Attr) isV7 = Attr.value() == ARMBuildAttrs::v7; @@ -303,7 +303,8 @@ SubtargetFeatures ELFObjectFileBase::getRISCVFeatures() const { return Features; // Keep "c" feature if there is one in PlatformFlags. } - Optional Attr = Attributes.getAttributeString(RISCVAttrs::ARCH); + std::optional Attr = + Attributes.getAttributeString(RISCVAttrs::ARCH); if (Attr) { // The Arch pattern is [rv32|rv64][i|e]version(_[m|a|f|d|c]version)* // Version string pattern is (major)p(minor). Major and minor are optional. @@ -542,7 +543,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const { else Triple = "arm"; - Optional Attr = + std::optional Attr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch); if (Attr) { switch (Attr.value()) { @@ -574,7 +575,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const { Triple += "v6k"; break; case ARMBuildAttrs::v7: { - Optional ArchProfileAttr = + std::optional ArchProfileAttr = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile); if (ArchProfileAttr && ArchProfileAttr.value() == ARMBuildAttrs::MicroControllerProfile) diff --git a/llvm/unittests/Support/ARMAttributeParser.cpp b/llvm/unittests/Support/ARMAttributeParser.cpp index 7293c564..ef3da3f 100644 --- a/llvm/unittests/Support/ARMAttributeParser.cpp +++ b/llvm/unittests/Support/ARMAttributeParser.cpp @@ -37,7 +37,7 @@ bool testBuildAttr(unsigned Tag, unsigned Value, ARMAttributeParser Parser; cantFail(Parser.parse(Bytes, support::little)); - Optional Attr = Parser.getAttributeValue(ExpectedTag); + std::optional Attr = Parser.getAttributeValue(ExpectedTag); return Attr && *Attr == ExpectedValue; } diff --git a/llvm/unittests/Support/CSKYAttributeParserTest.cpp b/llvm/unittests/Support/CSKYAttributeParserTest.cpp index e857237..d3967fb 100644 --- a/llvm/unittests/Support/CSKYAttributeParserTest.cpp +++ b/llvm/unittests/Support/CSKYAttributeParserTest.cpp @@ -83,7 +83,7 @@ static bool testAttributeInt(unsigned Tag, unsigned Value, unsigned ExpectedTag, CSKYAttributeParser Parser; cantFail(Parser.parse(Bytes, support::little)); - Optional Attr = Parser.getAttributeValue(ExpectedTag); + std::optional Attr = Parser.getAttributeValue(ExpectedTag); return Attr && *Attr == ExpectedValue; } @@ -100,7 +100,7 @@ static bool testAttributeString(unsigned Tag, const char *Value, CSKYAttributeParser Parser; cantFail(Parser.parse(Bytes, support::little)); - Optional Attr = Parser.getAttributeString(ExpectedTag); + std::optional Attr = Parser.getAttributeString(ExpectedTag); return Attr && *Attr == ExpectedValue; } diff --git a/llvm/unittests/Support/RISCVAttributeParserTest.cpp b/llvm/unittests/Support/RISCVAttributeParserTest.cpp index a3aa88a..cdbec0c 100644 --- a/llvm/unittests/Support/RISCVAttributeParserTest.cpp +++ b/llvm/unittests/Support/RISCVAttributeParserTest.cpp @@ -44,7 +44,7 @@ static bool testAttribute(unsigned Tag, unsigned Value, unsigned ExpectedTag, RISCVAttributeParser Parser; cantFail(Parser.parse(Bytes, support::little)); - Optional Attr = Parser.getAttributeValue(ExpectedTag); + std::optional Attr = Parser.getAttributeValue(ExpectedTag); return Attr && *Attr == ExpectedValue; } -- 2.7.4