Author: Charles Zablit Date: 2026-01-29T16:57:31Z New Revision: 8a4244b560f3e760e07c50f543ef3810859d1e46
URL: https://github.com/llvm/llvm-project/commit/8a4244b560f3e760e07c50f543ef3810859d1e46 DIFF: https://github.com/llvm/llvm-project/commit/8a4244b560f3e760e07c50f543ef3810859d1e46.diff LOG: [lldb][windows] fix unchecked Expected<T> (#178681) This patch fixes unchecked `Expected<T>` returns from the `CompilerType::GetByteSize` method. Added: Modified: lldb/include/lldb/Target/ProcessStructReader.h lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/source/ValueObject/ValueObject.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Target/ProcessStructReader.h b/lldb/include/lldb/Target/ProcessStructReader.h index 0f0b3f69d5509..df3203698afd0 100644 --- a/lldb/include/lldb/Target/ProcessStructReader.h +++ b/lldb/include/lldb/Target/ProcessStructReader.h @@ -16,6 +16,7 @@ #include "lldb/Target/Process.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Status.h" #include "llvm/ADT/StringMap.h" @@ -59,21 +60,32 @@ class ProcessStructReader { // no support for bitfields in here (yet) if (is_bitfield) return; - auto size = field_type.GetByteSize(nullptr); + auto size_or_err = field_type.GetByteSize(nullptr); + if (!size_or_err) { + LLDB_LOG_ERROR(GetLog(LLDBLog::Target), size_or_err.takeError(), "{0}"); + return; + } + size_t size = *size_or_err; + // no support for things larger than a uint64_t (yet) - if (!size || *size > 8) + if (size > 8) return; size_t byte_index = static_cast<size_t>(bit_offset / 8); - m_fields.insert({name, FieldImpl{field_type, byte_index, - static_cast<size_t>(*size)}}); + m_fields.insert( + {name, FieldImpl{field_type, byte_index, static_cast<size_t>(size)}}); } - auto total_size = struct_type.GetByteSize(nullptr); - if (!total_size) + auto total_size_or_err = struct_type.GetByteSize(nullptr); + if (!total_size_or_err) { + LLDB_LOG_ERROR(GetLog(LLDBLog::Target), total_size_or_err.takeError(), + "{0}"); return; - lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(*total_size, 0)); + } + size_t total_size = *total_size_or_err; + + lldb::WritableDataBufferSP buffer_sp(new DataBufferHeap(total_size, 0)); Status error; process->ReadMemoryFromInferior(base_addr, buffer_sp->GetBytes(), - *total_size, error); + total_size, error); if (error.Fail()) return; m_data = DataExtractor(buffer_sp, m_byte_order, m_addr_byte_size); diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 34d97a07d73fc..478f10a60a865 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -885,11 +885,15 @@ lldb::BasicType TypeSystemClang::GetBasicTypeEnumeration(llvm::StringRef name) { } uint32_t TypeSystemClang::GetPointerByteSize() { - if (m_pointer_byte_size == 0) - if (auto size = GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType() - .GetByteSize(nullptr)) - m_pointer_byte_size = *size; + if (m_pointer_byte_size != 0) + return m_pointer_byte_size; + auto size_or_err = + GetBasicType(lldb::eBasicTypeVoid).GetPointerType().GetByteSize(nullptr); + if (!size_or_err) { + LLDB_LOG_ERROR(GetLog(LLDBLog::Types), size_or_err.takeError(), "{0}"); + return m_pointer_byte_size; + } + m_pointer_byte_size = *size_or_err; return m_pointer_byte_size; } diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp index 121054e3e92ed..9c453e06b1c31 100644 --- a/lldb/source/ValueObject/ValueObject.cpp +++ b/lldb/source/ValueObject/ValueObject.cpp @@ -744,8 +744,8 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx, } } break; case eAddressTypeHost: { - auto max_bytes = - GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); + auto max_bytes = llvm::expectedToOptional(GetCompilerType().GetByteSize( + exe_ctx.GetBestExecutionContextScope())); if (max_bytes && *max_bytes > offset) { size_t bytes_read = std::min<uint64_t>(*max_bytes - offset, bytes); addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
