[Lldb-commits] [lldb] r349970 - [Scalar] Implement operator!= using operator==.
Davide Italiano via lldb-commits
lldb-commits at lists.llvm.org
Fri Dec 21 14:42:00 PST 2018
Author: davide
Date: Fri Dec 21 14:42:00 2018
New Revision: 349970
URL: http://llvm.org/viewvc/llvm-project?rev=349970&view=rev
Log:
[Scalar] Implement operator!= using operator==.
Summary: Adding some test coverage while I'm around.
Reviewers: JDevlieghere, aprantl, zturner, clayborg, jingham
Differential Revision: https://reviews.llvm.org/D56017
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=349970&r1=349969&r2=349970&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Scalar.cpp (original)
+++ lldb/trunk/source/Utility/Scalar.cpp Fri Dec 21 14:42:00 2018
@@ -2598,37 +2598,7 @@ bool lldb_private::operator==(const Scal
}
bool lldb_private::operator!=(const Scalar &lhs, const Scalar &rhs) {
- // If either entry is void then we can just compare the types
- if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
- return lhs.m_type != rhs.m_type;
-
- Scalar
- temp_value; // A temp value that might get a copy of either promoted 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_uint:
- case Scalar::e_slong:
- case Scalar::e_ulong:
- case Scalar::e_slonglong:
- case Scalar::e_ulonglong:
- case Scalar::e_sint128:
- case Scalar::e_uint128:
- case Scalar::e_sint256:
- case Scalar::e_uint256:
- return a->m_integer != 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::cmpEqual)
- return true;
- }
- return true;
+ return !(lhs == rhs);
}
bool lldb_private::operator<(const Scalar &lhs, const Scalar &rhs) {
Modified: lldb/trunk/unittests/Utility/ScalarTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ScalarTest.cpp?rev=349970&r1=349969&r2=349970&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ScalarTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ScalarTest.cpp Fri Dec 21 14:42:00 2018
@@ -19,6 +19,33 @@
using namespace lldb_private;
using namespace llvm;
+template <typename T>
+bool checkInequality(T c1, T c2) {
+ return (Scalar(c1) != Scalar(c2));
+}
+
+template <typename T>
+bool checkEquality(T c1, T c2) {
+ return (Scalar(c1) == Scalar(c2));
+}
+
+TEST(ScalarTest, Equality) {
+ ASSERT_TRUE(checkInequality<int>(23, 24));
+ ASSERT_TRUE(checkEquality<int>(96, 96));
+ ASSERT_TRUE(checkInequality<float>(4.0f, 4.5f));
+ ASSERT_TRUE(checkEquality<float>(4.0f, 4.0f));
+ uint64_t apint1 = 234;
+ uint64_t apint2 = 246;
+ ASSERT_TRUE(checkInequality<APInt>(APInt(64, apint1), APInt(64, apint2)));
+ ASSERT_TRUE(checkEquality<APInt>(APInt(64, apint1), APInt(64, apint1)));
+
+ Scalar void1;
+ Scalar void2;
+ float f1 = 2.0;
+ ASSERT_TRUE(void1 == void2);
+ ASSERT_FALSE(void1 == Scalar(f1));
+}
+
TEST(ScalarTest, RightShiftOperator) {
int a = 0x00001000;
int b = 0xFFFFFFFF;
More information about the lldb-commits
mailing list