[llvm] 6aebb5d - AttributeParser: Convert Optional to std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 23:43:23 PST 2022


Author: Fangrui Song
Date: 2022-12-02T07:43:18Z
New Revision: 6aebb5d17765c1f9946d2281c9f697328799cde4

URL: https://github.com/llvm/llvm-project/commit/6aebb5d17765c1f9946d2281c9f697328799cde4
DIFF: https://github.com/llvm/llvm-project/commit/6aebb5d17765c1f9946d2281c9f697328799cde4.diff

LOG: AttributeParser: Convert Optional to std::optional

Added: 
    

Modified: 
    llvm/include/llvm/Support/ELFAttributeParser.h
    llvm/lib/Object/ELFObjectFile.cpp
    llvm/unittests/Support/ARMAttributeParser.cpp
    llvm/unittests/Support/CSKYAttributeParserTest.cpp
    llvm/unittests/Support/RISCVAttributeParserTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/ELFAttributeParser.h b/llvm/include/llvm/Support/ELFAttributeParser.h
index 89a1acc8a1f9..75ed82b3f683 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 <optional>
 #include <unordered_map>
 
 namespace llvm {
@@ -59,16 +60,16 @@ class ELFAttributeParser {
 
   Error parse(ArrayRef<uint8_t> section, support::endianness endian);
 
-  Optional<unsigned> getAttributeValue(unsigned tag) const {
+  std::optional<unsigned> getAttributeValue(unsigned tag) const {
     auto I = attributes.find(tag);
     if (I == attributes.end())
-      return None;
+      return std::nullopt;
     return I->second;
   }
-  Optional<StringRef> getAttributeString(unsigned tag) const {
+  std::optional<StringRef> 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 5726299591c8..31f009086612 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<unsigned> Attr =
+  std::optional<unsigned> 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<StringRef> Attr = Attributes.getAttributeString(RISCVAttrs::ARCH);
+  std::optional<StringRef> 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<unsigned> Attr =
+  std::optional<unsigned> 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<unsigned> ArchProfileAttr =
+      std::optional<unsigned> 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 7293c5649558..ef3da3fc7504 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<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
+  std::optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
   return Attr && *Attr == ExpectedValue;
 }
 

diff  --git a/llvm/unittests/Support/CSKYAttributeParserTest.cpp b/llvm/unittests/Support/CSKYAttributeParserTest.cpp
index e857237a68a5..d3967fb0ea3c 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<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
+  std::optional<unsigned> 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<StringRef> Attr = Parser.getAttributeString(ExpectedTag);
+  std::optional<StringRef> Attr = Parser.getAttributeString(ExpectedTag);
   return Attr && *Attr == ExpectedValue;
 }
 

diff  --git a/llvm/unittests/Support/RISCVAttributeParserTest.cpp b/llvm/unittests/Support/RISCVAttributeParserTest.cpp
index a3aa88a91b2f..cdbec0cf2ddb 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<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
+  std::optional<unsigned> Attr = Parser.getAttributeValue(ExpectedTag);
   return Attr && *Attr == ExpectedValue;
 }
 


        


More information about the llvm-commits mailing list