[llvm] 7403458 - Support: Convert some Optional to std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 00:02:25 PST 2022
Author: Fangrui Song
Date: 2022-12-02T08:02:19Z
New Revision: 74034588bd1cf719f4838c57583bdd1e1ceb1064
URL: https://github.com/llvm/llvm-project/commit/74034588bd1cf719f4838c57583bdd1e1ceb1064
DIFF: https://github.com/llvm/llvm-project/commit/74034588bd1cf719f4838c57583bdd1e1ceb1064.diff
LOG: Support: Convert some Optional to std::optional
Added:
Modified:
lld/ELF/InputFiles.cpp
llvm/include/llvm/Support/ELFAttributes.h
llvm/include/llvm/Support/LineIterator.h
llvm/lib/Support/ELFAttributes.cpp
llvm/lib/Support/LineIterator.cpp
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Removed:
################################################################################
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 6aca878987ce..7edb69655638 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -98,7 +98,7 @@ static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
// the input objects have been compiled.
static void updateARMVFPArgs(const ARMAttributeParser &attributes,
const InputFile *f) {
- Optional<unsigned> attr =
+ std::optional<unsigned> attr =
attributes.getAttributeValue(ARMBuildAttrs::ABI_VFP_args);
if (!attr)
// If an ABI tag isn't present then it is implicitly given the value of 0
@@ -145,7 +145,7 @@ static void updateARMVFPArgs(const ARMAttributeParser &attributes,
// is compiled with an architecture that supports these features then lld is
// permitted to use them.
static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
- Optional<unsigned> attr =
+ std::optional<unsigned> attr =
attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);
if (!attr)
return;
diff --git a/llvm/include/llvm/Support/ELFAttributes.h b/llvm/include/llvm/Support/ELFAttributes.h
index c8a7ae142b9a..295d0f466981 100644
--- a/llvm/include/llvm/Support/ELFAttributes.h
+++ b/llvm/include/llvm/Support/ELFAttributes.h
@@ -11,6 +11,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
+#include <optional>
namespace llvm {
@@ -27,7 +28,7 @@ enum AttrType : unsigned { File = 1, Section = 2, Symbol = 3 };
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
bool hasTagPrefix = true);
-Optional<unsigned> attrTypeFromString(StringRef tag, TagNameMap tagNameMap);
+std::optional<unsigned> attrTypeFromString(StringRef tag, TagNameMap tagNameMap);
// Magic numbers for ELF attributes.
enum AttrMagic { Format_Version = 0x41 };
diff --git a/llvm/include/llvm/Support/LineIterator.h b/llvm/include/llvm/Support/LineIterator.h
index 01cf7e061505..fc6871baf99a 100644
--- a/llvm/include/llvm/Support/LineIterator.h
+++ b/llvm/include/llvm/Support/LineIterator.h
@@ -9,11 +9,11 @@
#ifndef LLVM_SUPPORT_LINEITERATOR_H
#define LLVM_SUPPORT_LINEITERATOR_H
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/MemoryBufferRef.h"
#include <iterator>
+#include <optional>
namespace llvm {
@@ -31,7 +31,7 @@ class MemoryBuffer;
///
/// Note that this iterator requires the buffer to be nul terminated.
class line_iterator {
- Optional<MemoryBufferRef> Buffer;
+ std::optional<MemoryBufferRef> Buffer;
char CommentMarker = '\0';
bool SkipBlanks = true;
diff --git a/llvm/lib/Support/ELFAttributes.cpp b/llvm/lib/Support/ELFAttributes.cpp
index 5be38825d6c6..87e8c6f5cd35 100644
--- a/llvm/lib/Support/ELFAttributes.cpp
+++ b/llvm/lib/Support/ELFAttributes.cpp
@@ -21,8 +21,8 @@ StringRef ELFAttrs::attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
return hasTagPrefix ? tagName : tagName.drop_front(4);
}
-Optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
- TagNameMap tagNameMap) {
+std::optional<unsigned> ELFAttrs::attrTypeFromString(StringRef tag,
+ TagNameMap tagNameMap) {
bool hasTagPrefix = tag.startswith("Tag_");
auto tagNameIt =
find_if(tagNameMap, [tag, hasTagPrefix](const TagNameItem item) {
diff --git a/llvm/lib/Support/LineIterator.cpp b/llvm/lib/Support/LineIterator.cpp
index 9874d16d19e1..0a53002572fe 100644
--- a/llvm/lib/Support/LineIterator.cpp
+++ b/llvm/lib/Support/LineIterator.cpp
@@ -37,7 +37,8 @@ line_iterator::line_iterator(const MemoryBuffer &Buffer, bool SkipBlanks,
line_iterator::line_iterator(const MemoryBufferRef &Buffer, bool SkipBlanks,
char CommentMarker)
- : Buffer(Buffer.getBufferSize() ? Optional<MemoryBufferRef>(Buffer) : None),
+ : Buffer(Buffer.getBufferSize() ? std::optional<MemoryBufferRef>(Buffer)
+ : std::nullopt),
CommentMarker(CommentMarker), SkipBlanks(SkipBlanks),
CurrentLine(Buffer.getBufferSize() ? Buffer.getBufferStart() : nullptr,
0) {
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index a581f8bbd97f..cdecb656aad0 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11399,7 +11399,7 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
- Optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
+ std::optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
Name, ARMBuildAttrs::getARMAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
diff --git a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
index 60eb552039bb..724f06fd21be 100644
--- a/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
+++ b/llvm/lib/Target/CSKY/AsmParser/CSKYAsmParser.cpp
@@ -1637,7 +1637,7 @@ bool CSKYAsmParser::parseDirectiveAttribute() {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
- Optional<unsigned> Ret =
+ std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, CSKYAttrs::getCSKYAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index b7bc416c8311..e4d5ad556d1b 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -2168,7 +2168,7 @@ bool RISCVAsmParser::parseDirectiveAttribute() {
TagLoc = Parser.getTok().getLoc();
if (Parser.getTok().is(AsmToken::Identifier)) {
StringRef Name = Parser.getTok().getIdentifier();
- Optional<unsigned> Ret =
+ std::optional<unsigned> Ret =
ELFAttrs::attrTypeFromString(Name, RISCVAttrs::getRISCVAttributeTags());
if (!Ret) {
Error(TagLoc, "attribute name not recognised: " + Name);
More information about the llvm-commits
mailing list