[Lldb-commits] [lldb] [lldb] Add pointer arithmetics for addition and subtraction to DIL (PR #184652)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 13 01:36:45 PDT 2026
================
@@ -602,6 +642,62 @@ llvm::Expected<lldb::ValueObjectSP> Interpreter::EvaluateBinarySubtraction(
if (result_type.IsScalarType())
return EvaluateScalarOp(BinaryOpKind::Sub, lhs, rhs, result_type, location);
+ auto lhs_type = lhs->GetCompilerType();
+ auto rhs_type = rhs->GetCompilerType();
+
+ // "pointer - integer" operation.
+ if (lhs_type.IsPointerType() && rhs_type.IsInteger())
+ return PointerAdd(lhs, -rhs->GetValueAsUnsigned(0), location);
----------------
Michael137 wrote:
Also, I know we probably aren't very diligent about this in most places, but I just noticed it here so I'll mention it. I think it'd be nicer if we did `llvm::joinErrors(llvm::createStringError("Failed to perform pointer addition:"), err.takeError())`
Just thinking from a user-perspective. If the byte-size of the element type was failed to be read, an expression like `(5 + otherPtr) + offsets[0]` would just say: `failed to read byte-size`. Probably nicer to be more specific about what part failed.
Wdyt? I'm not sure how such failures would present today, so I might be off-base
https://github.com/llvm/llvm-project/pull/184652
More information about the lldb-commits
mailing list