[clang-tools-extra] 49e75eb - [Bitcode(Reader|Writer)] Convert Optional to std::optional
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 7 15:27:58 PST 2022
Author: Krzysztof Parzyszek
Date: 2022-12-07T15:27:38-08:00
New Revision: 49e75ebd854dee1fcf5729c264f4cfadf76e952d
URL: https://github.com/llvm/llvm-project/commit/49e75ebd854dee1fcf5729c264f4cfadf76e952d
DIFF: https://github.com/llvm/llvm-project/commit/49e75ebd854dee1fcf5729c264f4cfadf76e952d.diff
LOG: [Bitcode(Reader|Writer)] Convert Optional to std::optional
Added:
Modified:
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeReader.h
clang/lib/Frontend/SerializedDiagnosticReader.cpp
llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
llvm/include/llvm/Bitstream/BitstreamReader.h
llvm/include/llvm/Bitstream/BitstreamWriter.h
llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/Bitstream/Reader/BitstreamReader.cpp
llvm/lib/Remarks/BitstreamRemarkParser.cpp
llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
llvm/unittests/Remarks/BitstreamRemarksSerializerTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 072011448330e..c6928f60f3970 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -8,7 +8,6 @@
#include "BitcodeReader.h"
#include "llvm/ADT/IndexedMap.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
@@ -795,7 +794,7 @@ llvm::Error ClangDocBitcodeReader::validateStream() {
}
llvm::Error ClangDocBitcodeReader::readBlockInfoBlock() {
- Expected<Optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
+ Expected<std::optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
Stream.ReadBlockInfoBlock();
if (!MaybeBlockInfo)
return MaybeBlockInfo.takeError();
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.h b/clang-tools-extra/clang-doc/BitcodeReader.h
index 91251fba29992..a046ee2f7a24a 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.h
+++ b/clang-tools-extra/clang-doc/BitcodeReader.h
@@ -18,10 +18,10 @@
#include "BitcodeWriter.h"
#include "Representation.h"
#include "clang/AST/AST.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Support/Error.h"
+#include <optional>
namespace clang {
namespace doc {
@@ -65,7 +65,7 @@ class ClangDocBitcodeReader {
llvm::Expected<std::unique_ptr<Info>> readBlockToInfo(unsigned ID);
llvm::BitstreamCursor &Stream;
- Optional<llvm::BitstreamBlockInfo> BlockInfo;
+ std::optional<llvm::BitstreamBlockInfo> BlockInfo;
FieldId CurrentReferenceField;
};
diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp
index 29ec7059fe9e2..5f5ed41b04629 100644
--- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp
+++ b/clang/lib/Frontend/SerializedDiagnosticReader.cpp
@@ -10,7 +10,6 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Frontend/SerializedDiagnostics.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitstream/BitCodes.h"
@@ -20,6 +19,7 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/ManagedStatic.h"
#include <cstdint>
+#include <optional>
#include <system_error>
using namespace clang;
@@ -35,7 +35,7 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
return SDError::CouldNotLoad;
llvm::BitstreamCursor Stream(**Buffer);
- Optional<llvm::BitstreamBlockInfo> BlockInfo;
+ std::optional<llvm::BitstreamBlockInfo> BlockInfo;
if (Stream.AtEndOfStream())
return SDError::InvalidSignature;
@@ -73,7 +73,7 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
switch (MaybeSubBlockID.get()) {
case llvm::bitc::BLOCKINFO_BLOCK_ID: {
- Expected<Optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
+ Expected<std::optional<llvm::BitstreamBlockInfo>> MaybeBlockInfo =
Stream.ReadBlockInfoBlock();
if (!MaybeBlockInfo) {
// FIXME this drops the error on the floor.
diff --git a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
index c345563b6d1a3..63ecf85133601 100644
--- a/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
+++ b/llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
@@ -14,11 +14,11 @@
#define LLVM_BITCODE_BITCODEANALYZER_H
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Support/Error.h"
#include <map>
+#include <optional>
#include <vector>
namespace llvm {
@@ -53,7 +53,7 @@ class BitcodeAnalyzer {
BitstreamCursor Stream;
BitstreamBlockInfo BlockInfo;
CurStreamTypeType CurStreamType;
- Optional<BitstreamCursor> BlockInfoStream;
+ std::optional<BitstreamCursor> BlockInfoStream;
unsigned NumTopBlocks = 0;
struct PerRecordStats {
@@ -86,18 +86,19 @@ class BitcodeAnalyzer {
public:
BitcodeAnalyzer(StringRef Buffer,
- Optional<StringRef> BlockInfoBuffer = std::nullopt);
+ std::optional<StringRef> BlockInfoBuffer = std::nullopt);
/// Analyze the bitcode file.
- Error analyze(Optional<BCDumpOptions> O = std::nullopt,
- Optional<StringRef> CheckHash = std::nullopt);
+ Error analyze(std::optional<BCDumpOptions> O = std::nullopt,
+ std::optional<StringRef> CheckHash = std::nullopt);
/// Print stats about the bitcode file.
- void printStats(BCDumpOptions O, Optional<StringRef> Filename = std::nullopt);
+ void printStats(BCDumpOptions O,
+ std::optional<StringRef> Filename = std::nullopt);
private:
/// Read a block, updating statistics, etc.
Error parseBlock(unsigned BlockID, unsigned IndentLevel,
- Optional<BCDumpOptions> O = std::nullopt,
- Optional<StringRef> CheckHash = std::nullopt);
+ std::optional<BCDumpOptions> O = std::nullopt,
+ std::optional<StringRef> CheckHash = std::nullopt);
Error decodeMetadataStringsBlob(StringRef Indent, ArrayRef<uint64_t> Record,
StringRef Blob, raw_ostream &OS);
diff --git a/llvm/include/llvm/Bitstream/BitstreamReader.h b/llvm/include/llvm/Bitstream/BitstreamReader.h
index 661dc7a871139..3a838309fb1ca 100644
--- a/llvm/include/llvm/Bitstream/BitstreamReader.h
+++ b/llvm/include/llvm/Bitstream/BitstreamReader.h
@@ -26,6 +26,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
+#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -564,7 +565,7 @@ class BitstreamCursor : SimpleBitstreamCursor {
///
/// \param ReadBlockInfoNames Whether to read block/record name information in
/// the BlockInfo block. Only llvm-bcanalyzer uses this.
- Expected<Optional<BitstreamBlockInfo>>
+ Expected<std::optional<BitstreamBlockInfo>>
ReadBlockInfoBlock(bool ReadBlockInfoNames = false);
/// Set the block info to be used by this BitstreamCursor to interpret
diff --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h
index f087061856734..0516d53b7be9a 100644
--- a/llvm/include/llvm/Bitstream/BitstreamWriter.h
+++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h
@@ -15,7 +15,6 @@
#define LLVM_BITSTREAM_BITSTREAMWRITER_H
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitstream/BitCodes.h"
@@ -23,6 +22,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
+#include <optional>
#include <vector>
namespace llvm {
@@ -370,7 +370,7 @@ class BitstreamWriter {
/// the code.
template <typename uintty>
void EmitRecordWithAbbrevImpl(unsigned Abbrev, ArrayRef<uintty> Vals,
- StringRef Blob, Optional<unsigned> Code) {
+ StringRef Blob, std::optional<unsigned> Code) {
const char *BlobData = Blob.data();
unsigned BlobLen = (unsigned) Blob.size();
unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
index bd80ee4efa585..7005011980ebc 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
@@ -13,6 +13,7 @@
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/SHA1.h"
+#include <optional>
using namespace llvm;
@@ -21,9 +22,9 @@ static Error reportError(StringRef Message) {
}
/// Return a symbolic block name if known, otherwise return null.
-static Optional<const char *> GetBlockName(unsigned BlockID,
- const BitstreamBlockInfo &BlockInfo,
- CurStreamTypeType CurStreamType) {
+static std::optional<const char *>
+GetBlockName(unsigned BlockID, const BitstreamBlockInfo &BlockInfo,
+ CurStreamTypeType CurStreamType) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID)
@@ -84,9 +85,10 @@ static Optional<const char *> GetBlockName(unsigned BlockID,
}
/// Return a symbolic code name if known, otherwise return null.
-static Optional<const char *> GetCodeName(unsigned CodeID, unsigned BlockID,
- const BitstreamBlockInfo &BlockInfo,
- CurStreamTypeType CurStreamType) {
+static std::optional<const char *>
+GetCodeName(unsigned CodeID, unsigned BlockID,
+ const BitstreamBlockInfo &BlockInfo,
+ CurStreamTypeType CurStreamType) {
// Standard blocks for all bitcode files.
if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
@@ -473,7 +475,7 @@ static Expected<CurStreamTypeType> ReadSignature(BitstreamCursor &Stream) {
return UnknownBitstream;
}
-static Expected<CurStreamTypeType> analyzeHeader(Optional<BCDumpOptions> O,
+static Expected<CurStreamTypeType> analyzeHeader(std::optional<BCDumpOptions> O,
BitstreamCursor &Stream) {
ArrayRef<uint8_t> Bytes = Stream.getBitcodeBytes();
const unsigned char *BufPtr = (const unsigned char *)Bytes.data();
@@ -553,14 +555,14 @@ Error BitcodeAnalyzer::decodeMetadataStringsBlob(StringRef Indent,
}
BitcodeAnalyzer::BitcodeAnalyzer(StringRef Buffer,
- Optional<StringRef> BlockInfoBuffer)
+ std::optional<StringRef> BlockInfoBuffer)
: Stream(Buffer) {
if (BlockInfoBuffer)
BlockInfoStream.emplace(*BlockInfoBuffer);
}
-Error BitcodeAnalyzer::analyze(Optional<BCDumpOptions> O,
- Optional<StringRef> CheckHash) {
+Error BitcodeAnalyzer::analyze(std::optional<BCDumpOptions> O,
+ std::optional<StringRef> CheckHash) {
if (Error E = analyzeHeader(O, Stream).moveInto(CurStreamType))
return E;
@@ -584,7 +586,7 @@ Error BitcodeAnalyzer::analyze(Optional<BCDumpOptions> O,
if (!MaybeBlockID)
return MaybeBlockID.takeError();
if (MaybeBlockID.get() == bitc::BLOCKINFO_BLOCK_ID) {
- Optional<BitstreamBlockInfo> NewBlockInfo;
+ std::optional<BitstreamBlockInfo> NewBlockInfo;
if (Error E =
BlockInfoCursor.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true)
.moveInto(NewBlockInfo))
@@ -621,7 +623,7 @@ Error BitcodeAnalyzer::analyze(Optional<BCDumpOptions> O,
}
void BitcodeAnalyzer::printStats(BCDumpOptions O,
- Optional<StringRef> Filename) {
+ std::optional<StringRef> Filename) {
uint64_t BufferSizeBits = Stream.getBitcodeBytes().size() * CHAR_BIT;
// Print a summary of the read file.
O.OS << "Summary ";
@@ -655,7 +657,7 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
O.OS << "Per-block Summary:\n";
for (const auto &Stat : BlockIDStats) {
O.OS << " Block ID #" << Stat.first;
- if (Optional<const char *> BlockName =
+ if (std::optional<const char *> BlockName =
GetBlockName(Stat.first, BlockInfo, CurStreamType))
O.OS << " (" << *BlockName << ")";
O.OS << ":\n";
@@ -718,7 +720,7 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
O.OS << " ";
O.OS << " ";
- if (Optional<const char *> CodeName = GetCodeName(
+ if (std::optional<const char *> CodeName = GetCodeName(
FreqPair.second, Stat.first, BlockInfo, CurStreamType))
O.OS << *CodeName << "\n";
else
@@ -730,8 +732,8 @@ void BitcodeAnalyzer::printStats(BCDumpOptions O,
}
Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
- Optional<BCDumpOptions> O,
- Optional<StringRef> CheckHash) {
+ std::optional<BCDumpOptions> O,
+ std::optional<StringRef> CheckHash) {
std::string Indent(IndentLevel * 2, ' ');
uint64_t BlockBitStart = Stream.GetCurrentBitNo();
@@ -745,7 +747,7 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
if (O && !O->DumpBlockinfo)
O->OS << Indent << "<BLOCKINFO_BLOCK/>\n";
- Optional<BitstreamBlockInfo> NewBlockInfo;
+ std::optional<BitstreamBlockInfo> NewBlockInfo;
if (Error E = Stream.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true)
.moveInto(NewBlockInfo))
return E;
@@ -766,7 +768,7 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
// Keep it for later, when we see a MODULE_HASH record
uint64_t BlockEntryPos = Stream.getCurrentByteNo();
- Optional<const char *> BlockName;
+ std::optional<const char *> BlockName;
if (DumpRecords) {
O->OS << Indent << "<";
if ((BlockName = GetBlockName(BlockID, BlockInfo, CurStreamType)))
@@ -860,7 +862,7 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
if (DumpRecords) {
O->OS << Indent << " <";
- Optional<const char *> CodeName =
+ std::optional<const char *> CodeName =
GetCodeName(Code, BlockID, BlockInfo, CurStreamType);
if (CodeName)
O->OS << *CodeName;
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index b5f185171ba1c..efc8b22f7f7b6 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -13,7 +13,6 @@
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
@@ -3717,11 +3716,11 @@ Error BitcodeReader::rememberAndSkipFunctionBodies() {
}
Error BitcodeReaderBase::readBlockInfo() {
- Expected<Optional<BitstreamBlockInfo>> MaybeNewBlockInfo =
+ Expected<std::optional<BitstreamBlockInfo>> MaybeNewBlockInfo =
Stream.ReadBlockInfoBlock();
if (!MaybeNewBlockInfo)
return MaybeNewBlockInfo.takeError();
- Optional<BitstreamBlockInfo> NewBlockInfo =
+ std::optional<BitstreamBlockInfo> NewBlockInfo =
std::move(MaybeNewBlockInfo.get());
if (!NewBlockInfo)
return error("Malformed block");
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 12358bbf8d0de..9c45ea00e8a09 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -17,7 +17,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -78,6 +77,7 @@
#include <iterator>
#include <map>
#include <memory>
+#include <optional>
#include <string>
#include <utility>
#include <vector>
@@ -525,7 +525,7 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
void writeModStrings();
void writeCombinedGlobalValueSummary();
- Optional<unsigned> getValueId(GlobalValue::GUID ValGUID) {
+ std::optional<unsigned> getValueId(GlobalValue::GUID ValGUID) {
auto VMI = GUIDToValueIdMap.find(ValGUID);
if (VMI == GUIDToValueIdMap.end())
return std::nullopt;
@@ -3811,7 +3811,7 @@ static void writeFunctionTypeMetadataRecords(BitstreamWriter &Stream,
Record.push_back(Arg.Calls.size());
for (auto &Call : Arg.Calls) {
Record.push_back(Call.ParamNo);
- Optional<unsigned> ValueID = GetValueID(Call.Callee);
+ std::optional<unsigned> ValueID = GetValueID(Call.Callee);
if (!ValueID) {
// If ValueID is unknown we can't drop just this call, we must drop
// entire parameter.
@@ -3975,7 +3975,7 @@ void ModuleBitcodeWriterBase::writePerModuleFunctionSummaryRecord(
FunctionSummary *FS = cast<FunctionSummary>(Summary);
writeFunctionTypeMetadataRecords(
- Stream, FS, [&](const ValueInfo &VI) -> Optional<unsigned> {
+ Stream, FS, [&](const ValueInfo &VI) -> std::optional<unsigned> {
return {VE.getValueID(VI.getValue())};
});
@@ -4429,7 +4429,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
return;
}
- auto GetValueId = [&](const ValueInfo &VI) -> Optional<unsigned> {
+ auto GetValueId = [&](const ValueInfo &VI) -> std::optional<unsigned> {
if (!VI)
return std::nullopt;
return getValueId(VI.getGUID());
@@ -4443,7 +4443,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
Stream, FS, CallsiteAbbrev, AllocAbbrev,
/*PerModule*/ false,
/*GetValueId*/ [&](const ValueInfo &VI) -> unsigned {
- Optional<unsigned> ValueID = GetValueId(VI);
+ std::optional<unsigned> ValueID = GetValueId(VI);
// This can happen in shared index files for distributed ThinLTO if
// the callee function summary is not included. Record 0 which we
// will have to deal with conservatively when doing any kind of
@@ -4499,7 +4499,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
for (auto &EI : FS->calls()) {
// If this GUID doesn't have a value id, it doesn't have a function
// summary and we don't need to record any calls to it.
- Optional<unsigned> CallValueId = GetValueId(EI.first);
+ std::optional<unsigned> CallValueId = GetValueId(EI.first);
if (!CallValueId)
continue;
NameVals.push_back(*CallValueId);
diff --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
index a3e37c6dbfce5..3cc9dfdf7b858 100644
--- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
+++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
@@ -9,6 +9,7 @@
#include "llvm/Bitstream/BitstreamReader.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
+#include <optional>
#include <string>
using namespace llvm;
@@ -417,7 +418,7 @@ Error BitstreamCursor::ReadAbbrevRecord() {
return Error::success();
}
-Expected<Optional<BitstreamBlockInfo>>
+Expected<std::optional<BitstreamBlockInfo>>
BitstreamCursor::ReadBlockInfoBlock(bool ReadBlockInfoNames) {
if (llvm::Error Err = EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID))
return std::move(Err);
diff --git a/llvm/lib/Remarks/BitstreamRemarkParser.cpp b/llvm/lib/Remarks/BitstreamRemarkParser.cpp
index 85fe814f1fda8..6dd032f07e72d 100644
--- a/llvm/lib/Remarks/BitstreamRemarkParser.cpp
+++ b/llvm/lib/Remarks/BitstreamRemarkParser.cpp
@@ -16,6 +16,7 @@
#include "llvm/Remarks/Remark.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include <optional>
using namespace llvm;
using namespace llvm::remarks;
@@ -230,7 +231,7 @@ Error BitstreamParserHelper::parseBlockInfoBlock() {
"Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
"BLOCKINFO_BLOCK, ...].");
- Expected<Optional<BitstreamBlockInfo>> MaybeBlockInfo =
+ Expected<std::optional<BitstreamBlockInfo>> MaybeBlockInfo =
Stream.ReadBlockInfoBlock();
if (!MaybeBlockInfo)
return MaybeBlockInfo.takeError();
diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
index 78c4251088bc0..610b479b08df6 100644
--- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -27,7 +27,6 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/Optional.h"
#include "llvm/Bitcode/BitcodeAnalyzer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
@@ -36,6 +35,7 @@
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
+#include <optional>
using namespace llvm;
static cl::OptionCategory BCAnalyzerCategory("BC Analyzer Options");
@@ -113,8 +113,9 @@ int main(int argc, char **argv) {
BlockInfoMB = ExitOnErr(openBitcodeFile(BlockInfoFilename));
BitcodeAnalyzer BA(MB->getBuffer(),
- BlockInfoMB ? Optional<StringRef>(BlockInfoMB->getBuffer())
- : std::nullopt);
+ BlockInfoMB
+ ? std::optional<StringRef>(BlockInfoMB->getBuffer())
+ : std::nullopt);
BCDumpOptions O(outs());
O.Histogram = !NoHistogram;
@@ -123,8 +124,8 @@ int main(int argc, char **argv) {
O.DumpBlockinfo = DumpBlockinfo;
ExitOnErr(BA.analyze(
- Dump ? Optional<BCDumpOptions>(O) : Optional<BCDumpOptions>(),
- CheckHash.empty() ? std::nullopt : Optional<StringRef>(CheckHash)));
+ Dump ? std::optional<BCDumpOptions>(O) : std::optional<BCDumpOptions>(),
+ CheckHash.empty() ? std::nullopt : std::optional<StringRef>(CheckHash)));
if (Dump)
outs() << "\n\n";
diff --git a/llvm/unittests/Remarks/BitstreamRemarksSerializerTest.cpp b/llvm/unittests/Remarks/BitstreamRemarksSerializerTest.cpp
index 50c50ecf027a7..8113d35b3aff8 100644
--- a/llvm/unittests/Remarks/BitstreamRemarksSerializerTest.cpp
+++ b/llvm/unittests/Remarks/BitstreamRemarksSerializerTest.cpp
@@ -11,6 +11,7 @@
#include "llvm/Remarks/Remark.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
+#include <optional>
#include <string>
// We need to supprt Windows paths as well. In order to have paths with the same
@@ -34,8 +35,8 @@ static void checkAnalyze(StringRef Input, StringRef Expected) {
}
static void check(remarks::SerializerMode Mode, const remarks::Remark &R,
- StringRef ExpectedR, Optional<StringRef> ExpectedMeta,
- Optional<remarks::StringTable> StrTab) {
+ StringRef ExpectedR, std::optional<StringRef> ExpectedMeta,
+ std::optional<remarks::StringTable> StrTab) {
// Emit the remark.
std::string InputBuf;
raw_string_ostream InputOS(InputBuf);
@@ -67,14 +68,14 @@ static void check(remarks::SerializerMode Mode, const remarks::Remark &R,
static void check(const remarks::Remark &R, StringRef ExpectedR,
StringRef ExpectedMeta,
- Optional<remarks::StringTable> StrTab = std::nullopt) {
+ std::optional<remarks::StringTable> StrTab = std::nullopt) {
return check(remarks::SerializerMode::Separate, R, ExpectedR, ExpectedMeta,
std::move(StrTab));
}
static void
checkStandalone(const remarks::Remark &R, StringRef ExpectedR,
- Optional<remarks::StringTable> StrTab = std::nullopt) {
+ std::optional<remarks::StringTable> StrTab = std::nullopt) {
return check(remarks::SerializerMode::Standalone, R, ExpectedR,
/*ExpectedMeta=*/std::nullopt, std::move(StrTab));
}
More information about the cfe-commits
mailing list