[Lldb-commits] [lldb] f43886e - [lldb] llvm::Optional::value() && => operator*/operator->
Fangrui Song via lldb-commits
lldb-commits at lists.llvm.org
Sat Dec 17 12:37:18 PST 2022
Author: Fangrui Song
Date: 2022-12-17T20:37:13Z
New Revision: f43886e7ba5abf9ee8c4d3f0ffbd18eee724466f
URL: https://github.com/llvm/llvm-project/commit/f43886e7ba5abf9ee8c4d3f0ffbd18eee724466f
DIFF: https://github.com/llvm/llvm-project/commit/f43886e7ba5abf9ee8c4d3f0ffbd18eee724466f.diff
LOG: [lldb] llvm::Optional::value() && => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
Added:
Modified:
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
lldb/source/Target/Thread.cpp
lldb/tools/lldb-test/lldb-test.cpp
lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 64bd2c3ddf207..a09fe64c7ac72 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -144,10 +144,10 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
"`frame diagnose --address` is incompatible with other arguments.");
return false;
}
- valobj_sp = frame_sp->GuessValueForAddress(m_options.address.value());
+ valobj_sp = frame_sp->GuessValueForAddress(*m_options.address);
} else if (m_options.reg) {
valobj_sp = frame_sp->GuessValueForRegisterAndOffset(
- m_options.reg.value(), m_options.offset.value_or(0));
+ *m_options.reg, m_options.offset.value_or(0));
} else {
StopInfoSP stop_info_sp = thread->GetStopInfo();
if (!stop_info_sp) {
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index e42665b974156..646747ec3758b 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1739,7 +1739,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
range_info.GetDirtyPageList();
if (dirty_page_list) {
- const size_t page_count = dirty_page_list.value().size();
+ const size_t page_count = dirty_page_list->size();
result.AppendMessageWithFormat(
"Modified memory (dirty) page list provided, %zu entries.\n",
page_count);
diff --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
index 1af60d25f7bc2..b78fbf7b750e6 100644
--- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
+++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
@@ -1214,8 +1214,7 @@ class Executor {
return transformOptional(inst.rs1.Read(m_emu),
[&](auto &&rs1) {
uint64_t addr = rs1 + uint64_t(inst.imm);
- uint64_t bits =
- m_emu.ReadMem<uint64_t>(addr).value();
+ uint64_t bits = *m_emu.ReadMem<uint64_t>(addr);
APFloat f(semantics(), APInt(numBits, bits));
return inst.rd.WriteAPFloat(m_emu, f);
})
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
index cf543ce48439f..70adc1d5a8a3d 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
@@ -55,8 +55,8 @@ Optional<ParsedName> CPlusPlusNameParser::ParseAsFullName() {
if (HasMoreTokens())
return std::nullopt;
ParsedName result;
- result.basename = GetTextForRange(name_ranges.value().basename_range);
- result.context = GetTextForRange(name_ranges.value().context_range);
+ result.basename = GetTextForRange(name_ranges->basename_range);
+ result.context = GetTextForRange(name_ranges->context_range);
return result;
}
@@ -130,8 +130,8 @@ CPlusPlusNameParser::ParseFunctionImpl(bool expect_return_type) {
SkipFunctionQualifiers();
size_t end_position = GetCurrentPosition();
- result.name.basename = GetTextForRange(maybe_name.value().basename_range);
- result.name.context = GetTextForRange(maybe_name.value().context_range);
+ result.name.basename = GetTextForRange(maybe_name->basename_range);
+ result.name.context = GetTextForRange(maybe_name->context_range);
result.arguments = GetTextForRange(Range(argument_start, qualifiers_start));
result.qualifiers = GetTextForRange(Range(qualifiers_start, end_position));
start_position.Remove();
@@ -709,10 +709,10 @@ CPlusPlusNameParser::ParseFullNameImpl() {
state == State::AfterTemplate) {
ParsedNameRanges result;
if (last_coloncolon_position) {
- result.context_range = Range(start_position.GetSavedPosition(),
- last_coloncolon_position.value());
+ result.context_range =
+ Range(start_position.GetSavedPosition(), *last_coloncolon_position);
result.basename_range =
- Range(last_coloncolon_position.value() + 1, GetCurrentPosition());
+ Range(*last_coloncolon_position + 1, GetCurrentPosition());
} else {
result.basename_range =
Range(start_position.GetSavedPosition(), GetCurrentPosition());
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index ade24dac65f32..5b4c5db2d9286 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -2049,7 +2049,7 @@ lldb::ValueObjectSP Thread::GetSiginfoValue() {
llvm::Optional<uint64_t> type_size = type.GetByteSize(nullptr);
assert(type_size);
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> data =
- GetSiginfo(type_size.value());
+ GetSiginfo(*type_size);
if (!data)
return ValueObjectConstResult::Create(&target, Status(data.takeError()));
diff --git a/lldb/tools/lldb-test/lldb-test.cpp b/lldb/tools/lldb-test/lldb-test.cpp
index 887cd14ffb63c..cb04ca5d50e23 100644
--- a/lldb/tools/lldb-test/lldb-test.cpp
+++ b/lldb/tools/lldb-test/lldb-test.cpp
@@ -883,7 +883,7 @@ static Mangled::NamePreference opts::symtab::getNamePreference() {
int opts::symtab::handleSymtabCommand(Debugger &Dbg) {
if (auto error = validate()) {
- logAllUnhandledErrors(std::move(error.value()), WithColor::error(), "");
+ logAllUnhandledErrors(std::move(*error), WithColor::error(), "");
return 1;
}
diff --git a/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp b/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
index 82cd49fdb0673..250ed6fe8fd37 100644
--- a/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
+++ b/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp
@@ -27,7 +27,7 @@ class ConnectionFileDescriptorTest : public testing::Test {
std::string uri(connection_file_descriptor.GetURI());
EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}),
- URI::Parse(uri).value());
+ *URI::Parse(uri));
}
};
diff --git a/lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp b/lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp
index 016992bd58ced..5bf7440c9e5bd 100644
--- a/lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp
+++ b/lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp
@@ -109,77 +109,76 @@ TEST(StringExtractorGDBRemoteTest, GetPidTid) {
// pure thread id
ex.Reset("-1");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(100, StringExtractorGDBRemote::AllThreads));
ex.Reset("1234");
- EXPECT_THAT(ex.GetPidTid(100).value(), ::testing::Pair(100, 0x1234ULL));
+ EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
ex.Reset("123456789ABCDEF0");
- EXPECT_THAT(ex.GetPidTid(100).value(),
- ::testing::Pair(100, 0x123456789ABCDEF0ULL));
+ EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x123456789ABCDEF0ULL));
// pure process id
ex.Reset("p-1");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
ex.Reset("p123456789ABCDEF0");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL,
StringExtractorGDBRemote::AllThreads));
ex.Reset("pFFFFFFFFFFFFFFFF");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
// combined thread id + process id
ex.Reset("p-1.-1");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234.-1");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234.123456789ABCDEF0");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, 0x123456789ABCDEF0ULL));
ex.Reset("p123456789ABCDEF0.-1");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p123456789ABCDEF0.1234");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x1234ULL));
ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
- EXPECT_THAT(ex.GetPidTid(100).value(),
+ EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
}
TEST(StringExtractorGDBRemoteTest, GetPidTidMultipleValues) {
StringExtractorGDBRemote ex("1234;p12;p1234.-1");
- ASSERT_THAT(ex.GetPidTid(100).value(), ::testing::Pair(100, 0x1234ULL));
+ ASSERT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
ASSERT_EQ(ex.GetChar(), ';');
- ASSERT_THAT(ex.GetPidTid(100).value(),
+ ASSERT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x12ULL, StringExtractorGDBRemote::AllThreads));
ASSERT_EQ(ex.GetChar(), ';');
- ASSERT_THAT(ex.GetPidTid(100).value(),
+ ASSERT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
}
More information about the lldb-commits
mailing list