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

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 15 14:57:47 PST 2025


https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/123107

>From f83e29d9b6fc747584485bae3f519dcd34a5bb0b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Wed, 15 Jan 2025 10:42:35 -0800
Subject: [PATCH 1/2] [lldb] Handle a byte size of zero in
 CompilerType::GetValueAsScalar

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 only a bunch of reports
of the lldb_assert triggering but no actual example that I could turn
into a test.

rdar://141630334
---
 lldb/source/Symbol/CompilerType.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index e9e6e3bf2600ced..3c4390b89a125aa 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -1105,7 +1105,7 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
       return false;
 
     std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
-    if (!byte_size)
+    if (!byte_size || *byte_size == 0)
       return false;
     lldb::offset_t offset = data_byte_offset;
     switch (encoding) {

>From 0c3d07e42545aa02a3aba6d5895cb645ae0bce34 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Wed, 15 Jan 2025 14:57:35 -0800
Subject: [PATCH 2/2] Add comment

---
 lldb/source/Symbol/CompilerType.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 3c4390b89a125aa..09820fb3f01017a 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);
+    // 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