[lldb][windows] fix unchecked Expected<T>#178681
Merged
charles-zablit merged 1 commit intollvm:mainfrom Jan 29, 2026
Merged
Conversation
Member
|
@llvm/pr-subscribers-lldb Author: Charles Zablit (charles-zablit) ChangesThis patch fixes unchecked Full diff: https://github.com/llvm/llvm-project/pull/178681.diff 3 Files Affected:
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);
|
adrian-prantl
approved these changes
Jan 29, 2026
Collaborator
adrian-prantl
left a comment
There was a problem hiding this comment.
Wow I am impressed this survived so long!
charles-zablit
added a commit
to charles-zablit/llvm-project
that referenced
this pull request
Jan 29, 2026
This patch fixes unchecked `Expected<T>` returns from the `CompilerType::GetByteSize` method. (cherry picked from commit 8a4244b)
honeygoyal
pushed a commit
to honeygoyal/llvm-project
that referenced
this pull request
Jan 30, 2026
This patch fixes unchecked `Expected<T>` returns from the `CompilerType::GetByteSize` method.
sshrestha-aa
pushed a commit
to sshrestha-aa/llvm-project
that referenced
this pull request
Feb 4, 2026
This patch fixes unchecked `Expected<T>` returns from the `CompilerType::GetByteSize` method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch fixes unchecked
Expected<T>returns from theCompilerType::GetByteSizemethod.