[Lldb-commits] [lldb] 96d1b4d - [lld] Don't use Optional::hasValue (NFC)
Kazu Hirata via lldb-commits
lldb-commits at lists.llvm.org
Sun Jun 26 19:29:48 PDT 2022
Author: Kazu Hirata
Date: 2022-06-26T19:29:40-07:00
New Revision: 96d1b4ddb2cc37b900692215f7598ff5970b0baa
URL: https://github.com/llvm/llvm-project/commit/96d1b4ddb2cc37b900692215f7598ff5970b0baa
DIFF: https://github.com/llvm/llvm-project/commit/96d1b4ddb2cc37b900692215f7598ff5970b0baa.diff
LOG: [lld] Don't use Optional::hasValue (NFC)
This patch replaces x.hasValue() with x where x is contextually
convertible to bool.
Added:
Modified:
lldb/include/lldb/Target/MemoryRegionInfo.h
lldb/source/API/SBMemoryRegionInfo.cpp
lldb/source/Breakpoint/BreakpointIDList.cpp
lldb/source/Commands/CommandObjectFrame.cpp
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Core/DataFileCache.cpp
lldb/source/Core/DumpDataExtractor.cpp
lldb/source/Core/ValueObjectChild.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
lldb/source/Target/UnixSignals.cpp
lldb/source/Utility/SelectHelper.cpp
lldb/unittests/tools/lldb-server/tests/TestClient.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h b/lldb/include/lldb/Target/MemoryRegionInfo.h
index acca66e838337..4e978d33b05dd 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -124,7 +124,7 @@ class MemoryRegionInfo {
void SetPageSize(int pagesize) { m_pagesize = pagesize; }
void SetDirtyPageList(std::vector<lldb::addr_t> pagelist) {
- if (m_dirty_pages.hasValue())
+ if (m_dirty_pages)
m_dirty_pages.getValue().clear();
m_dirty_pages = std::move(pagelist);
}
diff --git a/lldb/source/API/SBMemoryRegionInfo.cpp b/lldb/source/API/SBMemoryRegionInfo.cpp
index d0f74374476e0..e811bf31c7223 100644
--- a/lldb/source/API/SBMemoryRegionInfo.cpp
+++ b/lldb/source/API/SBMemoryRegionInfo.cpp
@@ -135,7 +135,7 @@ uint32_t SBMemoryRegionInfo::GetNumDirtyPages() {
uint32_t num_dirty_pages = 0;
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
m_opaque_up->GetDirtyPageList();
- if (dirty_page_list.hasValue())
+ if (dirty_page_list)
num_dirty_pages = dirty_page_list.getValue().size();
return num_dirty_pages;
@@ -147,7 +147,7 @@ addr_t SBMemoryRegionInfo::GetDirtyPageAddressAtIndex(uint32_t idx) {
addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
m_opaque_up->GetDirtyPageList();
- if (dirty_page_list.hasValue() && idx < dirty_page_list.getValue().size())
+ if (dirty_page_list && idx < dirty_page_list.getValue().size())
dirty_page_addr = dirty_page_list.getValue()[idx];
return dirty_page_addr;
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp
index b434056993640..dd16d3b6388c4 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -192,7 +192,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target,
auto start_bp = BreakpointID::ParseCanonicalReference(range_from);
auto end_bp = BreakpointID::ParseCanonicalReference(range_to);
- if (!start_bp.hasValue() ||
+ if (!start_bp ||
!target->GetBreakpointByID(start_bp->GetBreakpointID())) {
new_args.Clear();
result.AppendErrorWithFormat("'%s' is not a valid breakpoint ID.\n",
@@ -200,7 +200,7 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target,
return;
}
- if (!end_bp.hasValue() ||
+ if (!end_bp ||
!target->GetBreakpointByID(end_bp->GetBreakpointID())) {
new_args.Clear();
result.AppendErrorWithFormat("'%s' is not a valid breakpoint ID.\n",
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index 4081e87f2ddb9..93c41ee5a0be3 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -137,14 +137,14 @@ class CommandObjectFrameDiagnose : public CommandObjectParsed {
ValueObjectSP valobj_sp;
- if (m_options.address.hasValue()) {
- if (m_options.reg.hasValue() || m_options.offset.hasValue()) {
+ if (m_options.address) {
+ if (m_options.reg || m_options.offset) {
result.AppendError(
"`frame diagnose --address` is incompatible with other arguments.");
return false;
}
valobj_sp = frame_sp->GuessValueForAddress(m_options.address.getValue());
- } else if (m_options.reg.hasValue()) {
+ } else if (m_options.reg) {
valobj_sp = frame_sp->GuessValueForRegisterAndOffset(
m_options.reg.getValue(), m_options.offset.value_or(0));
} else {
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 117b5f468d4d7..98fa38f256351 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1737,7 +1737,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
range_info.GetDirtyPageList();
- if (dirty_page_list.hasValue()) {
+ if (dirty_page_list) {
const size_t page_count = dirty_page_list.getValue().size();
result.AppendMessageWithFormat(
"Modified memory (dirty) page list provided, %zu entries.\n",
diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp
index 5f8568fdb54f2..b38adfda169aa 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -203,17 +203,17 @@ bool CacheSignature::Encode(DataEncoder &encoder) const {
if (!IsValid())
return false; // Invalid signature, return false!
- if (m_uuid.hasValue()) {
+ if (m_uuid) {
llvm::ArrayRef<uint8_t> uuid_bytes = m_uuid->GetBytes();
encoder.AppendU8(eSignatureUUID);
encoder.AppendU8(uuid_bytes.size());
encoder.AppendData(uuid_bytes);
}
- if (m_mod_time.hasValue()) {
+ if (m_mod_time) {
encoder.AppendU8(eSignatureModTime);
encoder.AppendU32(*m_mod_time);
}
- if (m_obj_mod_time.hasValue()) {
+ if (m_obj_mod_time) {
encoder.AppendU8(eSignatureObjectModTime);
encoder.AppendU32(*m_obj_mod_time);
}
diff --git a/lldb/source/Core/DumpDataExtractor.cpp b/lldb/source/Core/DumpDataExtractor.cpp
index 211e16a2e0337..4ef1df1aeb0f8 100644
--- a/lldb/source/Core/DumpDataExtractor.cpp
+++ b/lldb/source/Core/DumpDataExtractor.cpp
@@ -118,7 +118,7 @@ static lldb::offset_t DumpAPInt(Stream *s, const DataExtractor &data,
lldb::offset_t offset, lldb::offset_t byte_size,
bool is_signed, unsigned radix) {
llvm::Optional<llvm::APInt> apint = GetAPInt(data, &offset, byte_size);
- if (apint.hasValue()) {
+ if (apint) {
std::string apint_str = toString(apint.getValue(), radix, is_signed);
switch (radix) {
case 2:
@@ -670,7 +670,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
(llvm::APFloat::getSizeInBits(semantics) + 7) / 8;
llvm::Optional<llvm::APInt> apint =
GetAPInt(DE, &offset, semantics_byte_size);
- if (apint.hasValue()) {
+ if (apint) {
llvm::APFloat apfloat(semantics, apint.getValue());
apfloat.toString(sv, format_precision, format_max_padding);
if (!sv.empty()) {
diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp
index a2beeb0bcdebe..d61d2021c3180 100644
--- a/lldb/source/Core/ValueObjectChild.cpp
+++ b/lldb/source/Core/ValueObjectChild.cpp
@@ -82,7 +82,7 @@ ConstString ValueObjectChild::GetDisplayTypeName() {
}
LazyBool ValueObjectChild::CanUpdateWithInvalidExecutionContext() {
- if (m_can_update_with_invalid_exe_ctx.hasValue())
+ if (m_can_update_with_invalid_exe_ctx)
return m_can_update_with_invalid_exe_ctx.getValue();
if (m_parent) {
ValueObject *opinionated_parent =
diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index e4c7e8fa3b83b..c85c66442510c 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1382,7 +1382,7 @@ const char *DisassemblerLLVMC::SymbolLookup(uint64_t value, uint64_t *type_ptr,
// the ADRP's register and this ADD's register are the same,
// then this is a pc-relative address calculation.
if (*type_ptr == LLVMDisassembler_ReferenceType_In_ARM64_ADDXri &&
- m_adrp_insn.hasValue() && m_adrp_address == pc - 4 &&
+ m_adrp_insn && m_adrp_address == pc - 4 &&
(m_adrp_insn.getValue() & 0x1f) == ((value >> 5) & 0x1f)) {
uint32_t addxri_inst;
uint64_t adrp_imm, addxri_imm;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index fdebfcd388ff9..81229dbe00459 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6516,7 +6516,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
addr_t pagesize = range_info.GetPageSize();
const llvm::Optional<std::vector<addr_t>> &dirty_page_list =
range_info.GetDirtyPageList();
- if (dirty_pages_only && dirty_page_list.hasValue()) {
+ if (dirty_pages_only && dirty_page_list) {
for (addr_t dirtypage : dirty_page_list.getValue()) {
page_object obj;
obj.addr = dirtypage;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 9f159f6188997..700e6ebdf84c1 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -2722,7 +2722,7 @@ bool GDBRemoteCommunicationClient::SetCurrentThread(uint64_t tid,
return true;
llvm::Optional<PidTid> ret = SendSetCurrentThreadPacket(tid, pid, 'g');
- if (ret.hasValue()) {
+ if (ret) {
if (ret->pid != LLDB_INVALID_PROCESS_ID)
m_curr_pid = ret->pid;
m_curr_tid = ret->tid;
@@ -2737,7 +2737,7 @@ bool GDBRemoteCommunicationClient::SetCurrentThreadForRun(uint64_t tid,
return true;
llvm::Optional<PidTid> ret = SendSetCurrentThreadPacket(tid, pid, 'c');
- if (ret.hasValue()) {
+ if (ret) {
if (ret->pid != LLDB_INVALID_PROCESS_ID)
m_curr_pid_run = ret->pid;
m_curr_tid_run = ret->tid;
diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
index 11175a410aa92..b5615c358b959 100644
--- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
+++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp
@@ -674,9 +674,9 @@ SymbolFileBreakpad::ParseCFIUnwindPlan(const Bookmark &bookmark,
plan_sp->AppendRow(row_sp);
for (++It; It != End; ++It) {
llvm::Optional<StackCFIRecord> record = StackCFIRecord::parse(*It);
- if (!record.hasValue())
+ if (!record)
return nullptr;
- if (record->Size.hasValue())
+ if (record->Size)
break;
row_sp = std::make_shared<UnwindPlan::Row>(*row_sp);
diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
index de1fdb8cc4202..4ae848a98eddd 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -300,14 +300,14 @@ UnixSignals::GetFilteredSignals(llvm::Optional<bool> should_suppress,
// If any of filtering conditions are not met, we move on to the next
// signal.
- if (should_suppress.hasValue() &&
+ if (should_suppress &&
signal_suppress != should_suppress.getValue())
continue;
- if (should_stop.hasValue() && signal_stop != should_stop.getValue())
+ if (should_stop && signal_stop != should_stop.getValue())
continue;
- if (should_notify.hasValue() && signal_notify != should_notify.getValue())
+ if (should_notify && signal_notify != should_notify.getValue())
continue;
result.push_back(signo);
diff --git a/lldb/source/Utility/SelectHelper.cpp b/lldb/source/Utility/SelectHelper.cpp
index eee6895296be6..a25bdfdaee8ec 100644
--- a/lldb/source/Utility/SelectHelper.cpp
+++ b/lldb/source/Utility/SelectHelper.cpp
@@ -161,15 +161,15 @@ lldb_private::Status SelectHelper::Select() {
fd_set write_fdset;
fd_set error_fdset;
- if (max_read_fd.hasValue()) {
+ if (max_read_fd) {
FD_ZERO(&read_fdset);
read_fdset_ptr = &read_fdset;
}
- if (max_write_fd.hasValue()) {
+ if (max_write_fd) {
FD_ZERO(&write_fdset);
write_fdset_ptr = &write_fdset;
}
- if (max_error_fd.hasValue()) {
+ if (max_error_fd) {
FD_ZERO(&error_fdset);
error_fdset_ptr = &error_fdset;
}
@@ -195,7 +195,7 @@ lldb_private::Status SelectHelper::Select() {
while (true) {
using namespace std::chrono;
// Setup out relative timeout based on the end time if we have one
- if (m_end_time.hasValue()) {
+ if (m_end_time) {
tv_ptr = &tv;
const auto remaining_dur = duration_cast<microseconds>(
m_end_time.getValue() - steady_clock::now());
diff --git a/lldb/unittests/tools/lldb-server/tests/TestClient.cpp b/lldb/unittests/tools/lldb-server/tests/TestClient.cpp
index 463dd226825eb..46ca10a03f69a 100644
--- a/lldb/unittests/tools/lldb-server/tests/TestClient.cpp
+++ b/lldb/unittests/tools/lldb-server/tests/TestClient.cpp
@@ -251,7 +251,7 @@ Error TestClient::queryProcess() {
}
Error TestClient::Continue(StringRef message) {
- assert(m_process_info.hasValue());
+ assert(m_process_info);
auto StopReplyOr = SendMessage<StopReply>(
message, m_process_info->GetEndian(), m_register_infos);
More information about the lldb-commits
mailing list