Skip to content

Commit 3b9d987

Browse files
committed
Adjust APInt bitwidth
1 parent 703232b commit 3b9d987

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lldb/source/ValueObject/DILEval.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,16 @@ Interpreter::Visit(const ScalarLiteralNode *node) {
503503
auto type = PickLiteralType(type_system, m_exe_ctx_scope, node);
504504
if (type) {
505505
Scalar scalar = node->GetValue();
506+
// APInt from StringRef::getAsInteger comes with just enough bitwidth to
507+
// hold the value. This adjusts APInt bitwidth to match the compiler type.
508+
if (scalar.GetType() == scalar.e_int) {
509+
auto apsint = scalar.GetAPSInt();
510+
auto type_bitsize = type->GetBitSize(m_exe_ctx_scope.get());
511+
if (type_bitsize) {
512+
llvm::APInt adjusted = apsint.zextOrTrunc(*type_bitsize);
513+
scalar = Scalar(adjusted);
514+
}
515+
}
506516
return ValueObject::CreateValueObjectFromScalar(m_target, scalar, *type,
507517
"result");
508518
} else

0 commit comments

Comments
 (0)