[Lldb-commits] [lldb] [lldb] Use APSInt's right shift operator in Scalar (PR #160149)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 22 09:44:19 PDT 2025
https://github.com/kuilpd created https://github.com/llvm/llvm-project/pull/160149
Right shift operator in `Scalar` didn't check if the value is unsigned to perform a logical right shift. Use the right shift operator from `APSInt` that does this check.
>From 085e848344f5772b3d1481c24ca6471fe45c9138 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Mon, 22 Sep 2025 20:05:57 +0500
Subject: [PATCH] [lldb] Use APSInt's right shift operator in Scalar
---
lldb/source/Utility/Scalar.cpp | 20 +++-----------------
lldb/unittests/Utility/ScalarTest.cpp | 3 +++
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c8766bdf2aee7..f2c18cdd896da 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -471,24 +471,10 @@ bool Scalar::ShiftRightLogical(const Scalar &rhs) {
}
Scalar &Scalar::operator>>=(const Scalar &rhs) {
- switch (m_type) {
- case e_void:
- case e_float:
+ if (m_type == e_int && rhs.m_type == e_int)
+ m_integer >>= rhs.m_integer.getZExtValue();
+ else
m_type = e_void;
- break;
-
- case e_int:
- switch (rhs.m_type) {
- case e_void:
- case e_float:
- m_type = e_void;
- break;
- case e_int:
- m_integer = m_integer.ashr(rhs.m_integer);
- break;
- }
- break;
- }
return *this;
}
diff --git a/lldb/unittests/Utility/ScalarTest.cpp b/lldb/unittests/Utility/ScalarTest.cpp
index 6d5caef42bee4..e6d7479b59fee 100644
--- a/lldb/unittests/Utility/ScalarTest.cpp
+++ b/lldb/unittests/Utility/ScalarTest.cpp
@@ -118,11 +118,14 @@ TEST(ScalarTest, RightShiftOperator) {
int a = 0x00001000;
int b = 0xFFFFFFFF;
int c = 4;
+ unsigned d = 0xFFFFFFFF;
Scalar a_scalar(a);
Scalar b_scalar(b);
Scalar c_scalar(c);
+ Scalar d_scalar(d);
ASSERT_EQ(a >> c, a_scalar >> c_scalar);
ASSERT_EQ(b >> c, b_scalar >> c_scalar);
+ ASSERT_EQ(d >> c, d_scalar >> c_scalar);
}
TEST(ScalarTest, GetBytes) {
More information about the lldb-commits
mailing list