[Lldb-commits] [lldb] [lldb] Zero extend APInt when piece size is bigger than the bitwidth (PR #150149)
satyanarayana reddy janga via lldb-commits
lldb-commits at lists.llvm.org
Sun Jul 27 14:50:37 PDT 2025
================
@@ -1978,7 +1978,12 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
// grows to the nearest host integer type.
llvm::APInt fail_value(1, 0, false);
llvm::APInt ap_int = scalar.UInt128(fail_value);
- assert(ap_int.getBitWidth() >= bit_size);
+ // We have seen a case where we have expression like:
+ // DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x28
+ // here we are assuming the compiler was trying to zero
+ // extend the value that we should append to the buffer.
+ if (ap_int.getBitWidth() < bit_size)
+ ap_int = ap_int.zext(bit_size);
llvm::ArrayRef<uint64_t> buf{ap_int.getRawData(),
ap_int.getNumWords()};
curr_piece.GetScalar() = Scalar(llvm::APInt(bit_size, buf));
----------------
satyajanga wrote:
> Isn't all of this equivalent to `curr_piece.GetScalar() = scalar.TruncOrExtendTo(bit_size, /*sign=*/false)`?
Yes. it seems so.
if the scalar has float value set then it wont work, but not sure if that case ever happens.
@labath do you know if the scalar contains a float value in the dwarf expression followed by DW_OP_Piece?
https://github.com/llvm/llvm-project/pull/150149
More information about the lldb-commits
mailing list