Skip to content

Commit 154e063

Browse files
authored
[lldb] Use APSInt's right shift operator in Scalar (#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.
1 parent 3ca5910 commit 154e063

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

lldb/source/Utility/Scalar.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -471,24 +471,10 @@ bool Scalar::ShiftRightLogical(const Scalar &rhs) {
471471
}
472472

473473
Scalar &Scalar::operator>>=(const Scalar &rhs) {
474-
switch (m_type) {
475-
case e_void:
476-
case e_float:
474+
if (m_type == e_int && rhs.m_type == e_int)
475+
m_integer >>= rhs.m_integer.getZExtValue();
476+
else
477477
m_type = e_void;
478-
break;
479-
480-
case e_int:
481-
switch (rhs.m_type) {
482-
case e_void:
483-
case e_float:
484-
m_type = e_void;
485-
break;
486-
case e_int:
487-
m_integer = m_integer.ashr(rhs.m_integer);
488-
break;
489-
}
490-
break;
491-
}
492478
return *this;
493479
}
494480

lldb/unittests/Utility/ScalarTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,17 @@ TEST(ScalarTest, RightShiftOperator) {
118118
int a = 0x00001000;
119119
int b = 0xFFFFFFFF;
120120
int c = 4;
121+
unsigned d = 0xFFFFFFFF;
122+
unsigned short e = 0xFFFF;
121123
Scalar a_scalar(a);
122124
Scalar b_scalar(b);
123125
Scalar c_scalar(c);
126+
Scalar d_scalar(d);
127+
Scalar e_scalar(e);
124128
ASSERT_EQ(a >> c, a_scalar >> c_scalar);
125129
ASSERT_EQ(b >> c, b_scalar >> c_scalar);
130+
ASSERT_EQ(d >> c, d_scalar >> c_scalar);
131+
ASSERT_EQ(e >> c, e_scalar >> c_scalar);
126132
}
127133

128134
TEST(ScalarTest, GetBytes) {

0 commit comments

Comments
 (0)