Skip to content

Commit 240b183

Browse files
committed
[lldb] Handle a byte size of zero in CompilerType::GetValueAsScalar (llvm#123107)
A bit or byte size of 0 is not a bug. It can legitimately (and frequently) happen in Swift and C, just not in C++. However, it doesn't make sense to read a scalar of zero bytes. Currently, when this happens, we trigger an `lldb_assert` in the data extractor and return 0, which isn't accurate. I have a bunch of reports of the assert triggering, but nobody has been able to provide me with a reproducer that I can turn into a test and I wasn't able to concoct a test case by reverse-engineering the code. rdar://141630334 (cherry picked from commit 8965dd4)
1 parent 14c8403 commit 240b183

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lldb/source/Symbol/CompilerType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,11 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
11191119
return false;
11201120

11211121
std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
1122-
if (!byte_size)
1122+
// A bit or byte size of 0 is not a bug, but it doesn't make sense to read a
1123+
// scalar of zero size.
1124+
if (!byte_size || *byte_size == 0)
11231125
return false;
1126+
11241127
lldb::offset_t offset = data_byte_offset;
11251128
switch (encoding) {
11261129
case lldb::eEncodingInvalid:

0 commit comments

Comments
 (0)