[Lldb-commits] [lldb] [lldb] Add pointer arithmetics for addition and subtraction to DIL (PR #184652)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 16 08:50:22 PDT 2026
================
@@ -538,6 +538,40 @@ Interpreter::Visit(const UnaryOpNode &node) {
node.GetLocation());
}
+llvm::Expected<lldb::ValueObjectSP>
+Interpreter::PointerOffset(lldb::ValueObjectSP ptr, lldb::ValueObjectSP offset,
+ bool positive, uint32_t location) {
+ if (ptr->GetCompilerType().IsPointerToVoid())
+ return llvm::make_error<DILDiagnosticError>(
+ m_expr, "arithmetic on a pointer to void", location);
+ if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
+ return llvm::make_error<DILDiagnosticError>(
+ m_expr, "arithmetic on a nullptr is undefined", location);
+
+ bool success;
+ int64_t offset_int = offset->GetValueAsSigned(0, &success);
----------------
kuilpd wrote:
> Why can't we just rely on the `offset` `ValueObject` to carry information about its signedness? If we just do `offset->GetValueAsSigned`, why is that always positive at the moment? Do we drop the signedness somewhere ealier, so we have to restore it here?
It's not always positive, it can be any value. My point that I have a single function that either subtracts that value or adds that value to the pointer. I pass an argument that signifies the operation itself. I realize that I made it really confusing by naming that argument `bool positive` initially.
I rewrote the code to hopefully make it more clear. Basically, it's this:
```
if (operation == BinaryOpKind::Sub)
addr = ptr->GetValueAsUnsigned(0) - offset_int * (*byte_size);
else
addr = ptr->GetValueAsUnsigned(0) + offset_int * (*byte_size);
```
https://github.com/llvm/llvm-project/pull/184652
More information about the lldb-commits
mailing list