[Lldb-commits] [lldb] 41a620d - [lldb] Fix 32-bit narrowing conversions in the memory cache (#223402)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 14 06:52:10 PDT 2026
Author: Yao Qi
Date: 2026-09-14T13:52:04Z
New Revision: 41a620da5a34d3e6256dc25e0c7c51c4afa8576d
URL: https://github.com/llvm/llvm-project/commit/41a620da5a34d3e6256dc25e0c7c51c4afa8576d
DIFF: https://github.com/llvm/llvm-project/commit/41a620da5a34d3e6256dc25e0c7c51c4afa8576d.diff
LOG: [lldb] Fix 32-bit narrowing conversions in the memory cache (#223402)
#222688 broke the 32-bit Arm bots. `lldb-arm-ubuntu` fails to
build `Memory.cpp`:
```
lldb/source/Target/Memory.cpp:187:49: error: non-constant-expression cannot be narrowed from type 'lldb::offset_t' (aka 'unsigned long long') to 'size_t' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]
187 | InsertData(addr, {data_buffer_sp->GetBytes(), data_buffer_sp->GetByteSize()});
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
`DataBuffer::GetByteSize` returns `lldb::offset_t`, which is always 64
bits wide, while the `llvm::ArrayRef` constructor takes a `size_t`.
Where
`size_t` is 32 bits the conversion narrows, and a braced initializer
list
rejects a narrowing conversion that is not a constant expression. The
same code compiles on a 64-bit host because there `size_t` is just as
wide
as `offset_t` and nothing narrows.
`DataBuffer::GetData` already returns the whole buffer as an
`llvm::ArrayRef<uint8_t>`, so use it rather than build the same
`ArrayRef`
from a pointer and a length.
`MemoryTest.cpp` has eight more of the same error, which the bot never
reported because the build stopped at the first one. They share a single
cause: `line` holds the cache line size, but it was declared `addr_t`
and
the `Chunk` field it initializes is a `size_t`. Give it the type
`MemoryCache::GetMemoryCacheLineSize` returns, `uint32_t`, which is also
the right domain for a size rather than an address.
Assisted-by: claude
Added:
Modified:
lldb/source/Target/Memory.cpp
lldb/unittests/Target/MemoryTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Target/Memory.cpp b/lldb/source/Target/Memory.cpp
index c7f58c8e52bb4..c2ad9e2c7ec3b 100644
--- a/lldb/source/Target/Memory.cpp
+++ b/lldb/source/Target/Memory.cpp
@@ -184,7 +184,7 @@ void MemoryCache::InsertData(addr_t addr, llvm::ArrayRef<uint8_t> src) {
void MemoryCache::AddCacheData(lldb::addr_t addr,
const DataBufferSP &data_buffer_sp) {
- InsertData(addr, {data_buffer_sp->GetBytes(), data_buffer_sp->GetByteSize()});
+ InsertData(addr, data_buffer_sp->GetData());
}
void MemoryCache::Flush(addr_t addr, size_t size) {
diff --git a/lldb/unittests/Target/MemoryTest.cpp b/lldb/unittests/Target/MemoryTest.cpp
index bf73d0724d3cf..e24e75d47a030 100644
--- a/lldb/unittests/Target/MemoryTest.cpp
+++ b/lldb/unittests/Target/MemoryTest.cpp
@@ -391,7 +391,7 @@ TEST_F(MemoryTest, TestCachePartition) {
ASSERT_TRUE(proc.GetProcess());
DummyProcess *process = proc.GetProcess();
TestMemoryCache mem_cache(*process);
- const lldb::addr_t line = process->GetMemoryCacheLineSize();
+ const uint32_t line = process->GetMemoryCacheLineSize();
ASSERT_EQ(line, 512u);
auto add = [&](lldb::addr_t addr, size_t size, uint8_t fill) {
More information about the lldb-commits
mailing list