[PATCH] D56017: [Scalar] Implement operator!= using operator==.

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 21 14:45:25 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL349970: [Scalar] Implement operator!= using operator==. (authored by davide, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D56017?vs=179363&id=179364#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56017/new/

https://reviews.llvm.org/D56017

Files:
  lldb/trunk/source/Utility/Scalar.cpp
  lldb/trunk/unittests/Utility/ScalarTest.cpp


Index: lldb/trunk/unittests/Utility/ScalarTest.cpp
===================================================================
--- lldb/trunk/unittests/Utility/ScalarTest.cpp
+++ lldb/trunk/unittests/Utility/ScalarTest.cpp
@@ -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;
Index: lldb/trunk/source/Utility/Scalar.cpp
===================================================================
--- lldb/trunk/source/Utility/Scalar.cpp
+++ lldb/trunk/source/Utility/Scalar.cpp
@@ -2598,37 +2598,7 @@
 }
 
 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56017.179364.patch
Type: text/x-patch
Size: 2485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181221/1784b4d3/attachment.bin>


More information about the llvm-commits mailing list