-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Use APSInt's right shift operator in Scalar #160149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-lldb Author: Ilia Kuklin (kuilpd) ChangesRight shift operator in Full diff: https://github.com/llvm/llvm-project/pull/160149.diff 2 Files Affected:
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) {
|
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a test for unsigned short?
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/181/builds/28439 Here is the relevant piece of the build log for the reference |
Right shift operator in
Scalardidn't check if the value is unsigned to perform a logical right shift. Use the right shift operator fromAPSIntthat does this check.