llvm.org GIT mirror llvm / 5e31044
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 Richard Trieu 8 years ago
1 changed file(s) with 20 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
134134 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
135135 return IsUnsigned ? uge(RHS) : sge(RHS);
136136 }
137 inline bool operator==(const APSInt& RHS) const {
138 assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
139 return eq(RHS);
140 }
141 inline bool operator==(int64_t RHS) const {
142 return isSameValue(*this, APSInt(APInt(64, RHS), true));
143 }
144 inline bool operator!=(const APSInt& RHS) const {
145 return !((*this) == RHS);
146 }
147 inline bool operator!=(int64_t RHS) const {
148 return !((*this) == RHS);
149 }
137150
138151 // The remaining operators just wrap the logic of APInt, but retain the
139152 // signedness information.
281294 void Profile(FoldingSetNodeID& ID) const;
282295 };
283296
297 inline bool operator==(int64_t V1, const APSInt& V2) {
298 return V2 == V1;
299 }
300 inline bool operator!=(int64_t V1, const APSInt& V2) {
301 return V2 != V1;
302 }
303
284304 inline raw_ostream &operator<<(raw_ostream &OS, const APSInt &I) {
285305 I.print(OS, I.isSigned());
286306 return OS;
287307 }
288308
289
290309 } // end namespace llvm
291310
292311 #endif