[Lldb-commits] [lldb] 3783db5 - [lldb] [NFC] Fix unused variable warning in MemoryCache::InsertPartialLine (#224973)
via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 21 01:28:19 PDT 2026
Author: Yao Qi
Date: 2026-09-21T09:28:13+01:00
New Revision: 3783db502a743ff25462590010c4d91d17c918b3
URL: https://github.com/llvm/llvm-project/commit/3783db502a743ff25462590010c4d91d17c918b3
DIFF: https://github.com/llvm/llvm-project/commit/3783db502a743ff25462590010c4d91d17c918b3.diff
LOG: [lldb] [NFC] Fix unused variable warning in MemoryCache::InsertPartialLine (#224973)
A Release build (assertions disabled) warns:
```
lldb/source/Target/Memory.cpp:144:18: warning: unused variable 'line_size' [-Wunused-variable]
144 | const uint32_t line_size = m_L2_cache.GetLineByteSize();
| ^~~~~~~~~
```
`line_size` was read only inside the `assert` that checks a partial-line
insert does not cross a cache line boundary. `assert` expands to nothing
when `NDEBUG` is defined, so the variable becomes unused in that
configuration.
`llvm/docs/CodingStandards.md` covers this shape directly:
```
In the first case, the call to `V.size()` is only useful for the assert,
and we don't want it executed when assertions are disabled. Code like
this should move the call into the assert itself.
```
so call `GetLineByteSize()` in the assert and drop the local.
Verified by building `lldb/source/Target/Memory.cpp` with
`-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF`: the warning
above reproduces before this change and is gone after it, with a clean
rebuild of the same object file.
Added:
Modified:
lldb/source/Target/Memory.cpp
Removed:
################################################################################
diff --git a/lldb/source/Target/Memory.cpp b/lldb/source/Target/Memory.cpp
index c2ad9e2c7ec3b..d7ceba345e119 100644
--- a/lldb/source/Target/Memory.cpp
+++ b/lldb/source/Target/Memory.cpp
@@ -141,9 +141,9 @@ void MemoryCache::InsertWholeLine(addr_t line_base_addr,
}
void MemoryCache::InsertPartialLine(addr_t addr, llvm::ArrayRef<uint8_t> src) {
- const uint32_t line_size = m_L2_cache.GetLineByteSize();
- assert(src.size() <= line_size &&
- addr / line_size == (addr + src.size() - 1) / line_size &&
+ assert(src.size() <= m_L2_cache.GetLineByteSize() &&
+ addr / m_L2_cache.GetLineByteSize() ==
+ (addr + src.size() - 1) / m_L2_cache.GetLineByteSize() &&
"a partial-line insert must not cross a cache line boundary");
// L2 holds only whole lines, so a range inside a resident line is held
// already.
More information about the lldb-commits
mailing list