[Lldb-commits] [lldb] r350428 - [Scalar] Simplify comparison operators and add coverage.
Davide Italiano via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 4 11:23:52 PST 2019
Author: davide
Date: Fri Jan 4 11:23:52 2019
New Revision: 350428
URL: http://llvm.org/viewvc/llvm-project?rev=350428&view=rev
Log:
[Scalar] Simplify comparison operators and add coverage.
Modified:
lldb/trunk/source/Utility/Scalar.cpp
lldb/trunk/unittests/Utility/ScalarTest.cpp
Modified: lldb/trunk/source/Utility/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Scalar.cpp?rev=350428&r1=350427&r2=350428&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Scalar.cpp (original)
+++ lldb/trunk/source/Utility/Scalar.cpp Fri Jan 4 11:23:52 2019
@@ -2635,104 +2635,15 @@ bool lldb_private::operator<(const Scala
}
bool lldb_private::operator<=(const Scalar &lhs, const Scalar &rhs) {
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar *a;
- const Scalar *b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
- case Scalar::e_void:
- break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- return a->m_integer.sle(b->m_integer);
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- return a->m_integer.ule(b->m_integer);
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if (result == llvm::APFloat::cmpLessThan ||
- result == llvm::APFloat::cmpEqual)
- return true;
- }
- return false;
+ return !(rhs < lhs);
}
bool lldb_private::operator>(const Scalar &lhs, const Scalar &rhs) {
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar *a;
- const Scalar *b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
- case Scalar::e_void:
- break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- return a->m_integer.sgt(b->m_integer);
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- return a->m_integer.ugt(b->m_integer);
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if (result == llvm::APFloat::cmpGreaterThan)
- return true;
- }
- return false;
+ return rhs < lhs;
}
bool lldb_private::operator>=(const Scalar &lhs, const Scalar &rhs) {
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return false;
-
- Scalar temp_value;
- const Scalar *a;
- const Scalar *b;
- llvm::APFloat::cmpResult result;
- switch (PromoteToMaxType(lhs, rhs, temp_value, a, b)) {
- case Scalar::e_void:
- break;
- case Scalar::e_sint:
- case Scalar::e_slong:
- case Scalar::e_slonglong:
- case Scalar::e_sint128:
- case Scalar::e_sint256:
- return a->m_integer.sge(b->m_integer);
- case Scalar::e_uint:
- case Scalar::e_ulong:
- case Scalar::e_ulonglong:
- case Scalar::e_uint128:
- case Scalar::e_uint256:
- return a->m_integer.uge(b->m_integer);
- case Scalar::e_float:
- case Scalar::e_double:
- case Scalar::e_long_double:
- result = a->m_float.compare(b->m_float);
- if (result == llvm::APFloat::cmpGreaterThan ||
- result == llvm::APFloat::cmpEqual)
- return true;
- }
- return false;
+ return !(lhs < rhs);
}
bool Scalar::ClearBit(uint32_t bit) {
Modified: lldb/trunk/unittests/Utility/ScalarTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ScalarTest.cpp?rev=350428&r1=350427&r2=350428&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ScalarTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ScalarTest.cpp Fri Jan 4 11:23:52 2019
@@ -47,6 +47,24 @@ TEST(ScalarTest, Equality) {
ASSERT_FALSE(void1 == Scalar(f1));
}
+TEST(ScalarTest, Comparison) {
+ auto s1 = Scalar(23);
+ auto s2 = Scalar(46);
+ ASSERT_TRUE(s1 < s2);
+ ASSERT_TRUE(s1 <= s2);
+ ASSERT_TRUE(s2 > s1);
+ ASSERT_TRUE(s2 >= s1);
+}
+
+TEST(ScalarTest, ComparisonFloat) {
+ auto s1 = Scalar(23.0f);
+ auto s2 = Scalar(46.0f);
+ ASSERT_TRUE(s1 < s2);
+ ASSERT_TRUE(s1 <= s2);
+ ASSERT_TRUE(s2 > s1);
+ ASSERT_TRUE(s2 >= s1);
+}
+
TEST(ScalarTest, RightShiftOperator) {
int a = 0x00001000;
int b = 0xFFFFFFFF;
More information about the lldb-commits
mailing list