diff options
author | Richard Trieu <rtrieu@google.com> | 2012-07-23 20:24:23 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2012-07-23 20:24:23 +0000 |
commit | 5e31044e119c75899b91ca97eb4d8ba786afc01c (patch) | |
tree | c2bf70e8b4849325f720dbdfa536d9ff418171e7 /include | |
parent | c72d3be38915728142d13f982eeef218e42f21aa (diff) | |
download | external_llvm-5e31044e119c75899b91ca97eb4d8ba786afc01c.zip external_llvm-5e31044e119c75899b91ca97eb4d8ba786afc01c.tar.gz external_llvm-5e31044e119c75899b91ca97eb4d8ba786afc01c.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160642 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/APSInt.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/include/llvm/ADT/APSInt.h b/include/llvm/ADT/APSInt.h index 807ca5e..048c65c 100644 --- a/include/llvm/ADT/APSInt.h +++ b/include/llvm/ADT/APSInt.h @@ -135,6 +135,19 @@ public: 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 @@ public: 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 |