[Lldb-commits] [lldb] 8965dd4 - [lldb] Handle a byte size of zero in CompilerType::GetValueAsScalar (#123107)

via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 16 09:34:02 PST 2025


Author: Jonas Devlieghere
Date: 2025-01-16T09:33:59-08:00
New Revision: 8965dd40c63cf00610fcf550017b46dae736d94b

URL: https://github.com/llvm/llvm-project/commit/8965dd40c63cf00610fcf550017b46dae736d94b
DIFF: https://github.com/llvm/llvm-project/commit/8965dd40c63cf00610fcf550017b46dae736d94b.diff

LOG: [lldb] Handle a byte size of zero in CompilerType::GetValueAsScalar (#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

Added: 
    

Modified: 
    lldb/source/Symbol/CompilerType.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index e9e6e3bf2600ce..09820fb3f01017 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -1105,8 +1105,11 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
       return false;
 
     std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
-    if (!byte_size)
+    // A bit or byte size of 0 is not a bug, but it doesn't make sense to read a
+    // scalar of zero size.
+    if (!byte_size || *byte_size == 0)
       return false;
+
     lldb::offset_t offset = data_byte_offset;
     switch (encoding) {
     case lldb::eEncodingInvalid:


        


More information about the lldb-commits mailing list