[llvm-commits] [llvm] r160642 - /llvm/trunk/include/llvm/ADT/APSInt.h

Richard Trieu rtrieu at google.com
Mon Jul 23 13:24:23 PDT 2012


Author: rtrieu
Date: Mon Jul 23 15:24:23 2012
New Revision: 160642

URL: http://llvm.org/viewvc/llvm-project?rev=160642&view=rev
Log:
Add operator== to APSInt.  This will compare the signed bit before doing
the comparison.  This prevents large unsigned integers from being equal to
signed negative integers of the same bit width.

Modified:
    llvm/trunk/include/llvm/ADT/APSInt.h

Modified: llvm/trunk/include/llvm/ADT/APSInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=160642&r1=160641&r2=160642&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APSInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APSInt.h Mon Jul 23 15:24:23 2012
@@ -135,6 +135,19 @@
     assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
     return IsUnsigned ? uge(RHS) : sge(RHS);
   }
+  inline bool operator==(const APSInt& RHS) const {
+    assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
+    return eq(RHS);
+  }
+  inline bool operator==(int64_t RHS) const {
+    return isSameValue(*this, APSInt(APInt(64, RHS), true));
+  }
+  inline bool operator!=(const APSInt& RHS) const {
+    return !((*this) == RHS);
+  }
+  inline bool operator!=(int64_t RHS) const {
+    return !((*this) == RHS);
+  }
 
   // The remaining operators just wrap the logic of APInt, but retain the
   // signedness information.
@@ -282,12 +295,18 @@
   void Profile(FoldingSetNodeID& ID) const;
 };
 
+inline bool operator==(int64_t V1, const APSInt& V2) {
+  return V2 == V1;
+}
+inline bool operator!=(int64_t V1, const APSInt& V2) {
+  return V2 != V1;
+}
+
 inline raw_ostream &operator<<(raw_ostream &OS, const APSInt &I) {
   I.print(OS, I.isSigned());
   return OS;
 }
 
-
 } // end namespace llvm
 
 #endif





More information about the llvm-commits mailing list