Annotate APInt methods where it's not clear whether they are in place with warn_unused_result.

Fix ScalarEvolution bugs uncovered by this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194928 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-11-16 16:25:41 +00:00
parent 4110797853
commit b69143c6a9
3 changed files with 47 additions and 41 deletions

View File

@ -765,7 +765,9 @@ public:
return APInt(getBitWidth(), VAL & RHS.VAL); return APInt(getBitWidth(), VAL & RHS.VAL);
return AndSlowCase(RHS); return AndSlowCase(RHS);
} }
APInt And(const APInt &RHS) const { return this->operator&(RHS); } APInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APInt &RHS) const {
return this->operator&(RHS);
}
/// \brief Bitwise OR operator. /// \brief Bitwise OR operator.
/// ///
@ -785,7 +787,9 @@ public:
/// calling operator|. /// calling operator|.
/// ///
/// \returns An APInt value representing the bitwise OR of *this and RHS. /// \returns An APInt value representing the bitwise OR of *this and RHS.
APInt Or(const APInt &RHS) const { return this->operator|(RHS); } APInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APInt &RHS) const {
return this->operator|(RHS);
}
/// \brief Bitwise XOR operator. /// \brief Bitwise XOR operator.
/// ///
@ -805,7 +809,9 @@ public:
/// through the usage of operator^. /// through the usage of operator^.
/// ///
/// \returns An APInt value representing the bitwise XOR of *this and RHS. /// \returns An APInt value representing the bitwise XOR of *this and RHS.
APInt Xor(const APInt &RHS) const { return this->operator^(RHS); } APInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APInt &RHS) const {
return this->operator^(RHS);
}
/// \brief Multiplication operator. /// \brief Multiplication operator.
/// ///
@ -837,17 +843,17 @@ public:
/// \brief Arithmetic right-shift function. /// \brief Arithmetic right-shift function.
/// ///
/// Arithmetic right-shift this APInt by shiftAmt. /// Arithmetic right-shift this APInt by shiftAmt.
APInt ashr(unsigned shiftAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const;
/// \brief Logical right-shift function. /// \brief Logical right-shift function.
/// ///
/// Logical right-shift this APInt by shiftAmt. /// Logical right-shift this APInt by shiftAmt.
APInt lshr(unsigned shiftAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const;
/// \brief Left-shift function. /// \brief Left-shift function.
/// ///
/// Left-shift this APInt by shiftAmt. /// Left-shift this APInt by shiftAmt.
APInt shl(unsigned shiftAmt) const { APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const {
assert(shiftAmt <= BitWidth && "Invalid shift amount"); assert(shiftAmt <= BitWidth && "Invalid shift amount");
if (isSingleWord()) { if (isSingleWord()) {
if (shiftAmt >= BitWidth) if (shiftAmt >= BitWidth)
@ -858,31 +864,31 @@ public:
} }
/// \brief Rotate left by rotateAmt. /// \brief Rotate left by rotateAmt.
APInt rotl(unsigned rotateAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(unsigned rotateAmt) const;
/// \brief Rotate right by rotateAmt. /// \brief Rotate right by rotateAmt.
APInt rotr(unsigned rotateAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(unsigned rotateAmt) const;
/// \brief Arithmetic right-shift function. /// \brief Arithmetic right-shift function.
/// ///
/// Arithmetic right-shift this APInt by shiftAmt. /// Arithmetic right-shift this APInt by shiftAmt.
APInt ashr(const APInt &shiftAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(const APInt &shiftAmt) const;
/// \brief Logical right-shift function. /// \brief Logical right-shift function.
/// ///
/// Logical right-shift this APInt by shiftAmt. /// Logical right-shift this APInt by shiftAmt.
APInt lshr(const APInt &shiftAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(const APInt &shiftAmt) const;
/// \brief Left-shift function. /// \brief Left-shift function.
/// ///
/// Left-shift this APInt by shiftAmt. /// Left-shift this APInt by shiftAmt.
APInt shl(const APInt &shiftAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(const APInt &shiftAmt) const;
/// \brief Rotate left by rotateAmt. /// \brief Rotate left by rotateAmt.
APInt rotl(const APInt &rotateAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(const APInt &rotateAmt) const;
/// \brief Rotate right by rotateAmt. /// \brief Rotate right by rotateAmt.
APInt rotr(const APInt &rotateAmt) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(const APInt &rotateAmt) const;
/// \brief Unsigned division operation. /// \brief Unsigned division operation.
/// ///
@ -890,12 +896,12 @@ public:
/// RHS are treated as unsigned quantities for purposes of this division. /// RHS are treated as unsigned quantities for purposes of this division.
/// ///
/// \returns a new APInt value containing the division result /// \returns a new APInt value containing the division result
APInt udiv(const APInt &RHS) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const;
/// \brief Signed division function for APInt. /// \brief Signed division function for APInt.
/// ///
/// Signed divide this APInt by APInt RHS. /// Signed divide this APInt by APInt RHS.
APInt sdiv(const APInt &RHS) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const;
/// \brief Unsigned remainder operation. /// \brief Unsigned remainder operation.
/// ///
@ -906,12 +912,12 @@ public:
/// is *this. /// is *this.
/// ///
/// \returns a new APInt value containing the remainder result /// \returns a new APInt value containing the remainder result
APInt urem(const APInt &RHS) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const;
/// \brief Function for signed remainder operation. /// \brief Function for signed remainder operation.
/// ///
/// Signed remainder operation on APInt. /// Signed remainder operation on APInt.
APInt srem(const APInt &RHS) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const;
/// \brief Dual division/remainder interface. /// \brief Dual division/remainder interface.
/// ///
@ -1145,7 +1151,7 @@ public:
/// ///
/// Truncate the APInt to a specified width. It is an error to specify a width /// Truncate the APInt to a specified width. It is an error to specify a width
/// that is greater than or equal to the current width. /// that is greater than or equal to the current width.
APInt trunc(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const;
/// \brief Sign extend to a new width. /// \brief Sign extend to a new width.
/// ///
@ -1153,38 +1159,38 @@ public:
/// bit is set, the fill on the left will be done with 1 bits, otherwise zero. /// bit is set, the fill on the left will be done with 1 bits, otherwise zero.
/// It is an error to specify a width that is less than or equal to the /// It is an error to specify a width that is less than or equal to the
/// current width. /// current width.
APInt sext(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const;
/// \brief Zero extend to a new width. /// \brief Zero extend to a new width.
/// ///
/// This operation zero extends the APInt to a new width. The high order bits /// This operation zero extends the APInt to a new width. The high order bits
/// are filled with 0 bits. It is an error to specify a width that is less /// are filled with 0 bits. It is an error to specify a width that is less
/// than or equal to the current width. /// than or equal to the current width.
APInt zext(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const;
/// \brief Sign extend or truncate to width /// \brief Sign extend or truncate to width
/// ///
/// Make this APInt have the bit width given by \p width. The value is sign /// Make this APInt have the bit width given by \p width. The value is sign
/// extended, truncated, or left alone to make it that width. /// extended, truncated, or left alone to make it that width.
APInt sextOrTrunc(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrTrunc(unsigned width) const;
/// \brief Zero extend or truncate to width /// \brief Zero extend or truncate to width
/// ///
/// Make this APInt have the bit width given by \p width. The value is zero /// Make this APInt have the bit width given by \p width. The value is zero
/// extended, truncated, or left alone to make it that width. /// extended, truncated, or left alone to make it that width.
APInt zextOrTrunc(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const;
/// \brief Sign extend or truncate to width /// \brief Sign extend or truncate to width
/// ///
/// Make this APInt have the bit width given by \p width. The value is sign /// Make this APInt have the bit width given by \p width. The value is sign
/// extended, or left alone to make it that width. /// extended, or left alone to make it that width.
APInt sextOrSelf(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrSelf(unsigned width) const;
/// \brief Zero extend or truncate to width /// \brief Zero extend or truncate to width
/// ///
/// Make this APInt have the bit width given by \p width. The value is zero /// Make this APInt have the bit width given by \p width. The value is zero
/// extended, or left alone to make it that width. /// extended, or left alone to make it that width.
APInt zextOrSelf(unsigned width) const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrSelf(unsigned width) const;
/// @} /// @}
/// \name Bit Manipulation Operators /// \name Bit Manipulation Operators
@ -1421,7 +1427,7 @@ public:
std::string toString(unsigned Radix, bool Signed) const; std::string toString(unsigned Radix, bool Signed) const;
/// \returns a byte-swapped representation of this APInt Value. /// \returns a byte-swapped representation of this APInt Value.
APInt byteSwap() const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const;
/// \brief Converts this APInt to a double value. /// \brief Converts this APInt to a double value.
double roundToDouble(bool isSigned) const; double roundToDouble(bool isSigned) const;
@ -1464,7 +1470,7 @@ public:
/// ///
/// The conversion does not do a translation from double to integer, it just /// The conversion does not do a translation from double to integer, it just
/// re-interprets the bits of the double. /// re-interprets the bits of the double.
static APInt doubleToBits(double V) { static APInt LLVM_ATTRIBUTE_UNUSED_RESULT doubleToBits(double V) {
union { union {
uint64_t I; uint64_t I;
double D; double D;
@ -1477,7 +1483,7 @@ public:
/// ///
/// The conversion does not do a translation from float to integer, it just /// The conversion does not do a translation from float to integer, it just
/// re-interprets the bits of the float. /// re-interprets the bits of the float.
static APInt floatToBits(float V) { static APInt LLVM_ATTRIBUTE_UNUSED_RESULT floatToBits(float V) {
union { union {
unsigned I; unsigned I;
float F; float F;
@ -1507,12 +1513,12 @@ public:
} }
/// \brief Compute the square root /// \brief Compute the square root
APInt sqrt() const; APInt LLVM_ATTRIBUTE_UNUSED_RESULT sqrt() const;
/// \brief Get the absolute value; /// \brief Get the absolute value;
/// ///
/// If *this is < 0 then return -(*this), otherwise *this; /// If *this is < 0 then return -(*this), otherwise *this;
APInt abs() const { APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const {
if (isNegative()) if (isNegative())
return -(*this); return -(*this);
return *this; return *this;

View File

@ -68,18 +68,18 @@ public:
} }
using APInt::toString; using APInt::toString;
APSInt trunc(uint32_t width) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(uint32_t width) const {
return APSInt(APInt::trunc(width), IsUnsigned); return APSInt(APInt::trunc(width), IsUnsigned);
} }
APSInt extend(uint32_t width) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extend(uint32_t width) const {
if (IsUnsigned) if (IsUnsigned)
return APSInt(zext(width), IsUnsigned); return APSInt(zext(width), IsUnsigned);
else else
return APSInt(sext(width), IsUnsigned); return APSInt(sext(width), IsUnsigned);
} }
APSInt extOrTrunc(uint32_t width) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const {
if (IsUnsigned) if (IsUnsigned)
return APSInt(zextOrTrunc(width), IsUnsigned); return APSInt(zextOrTrunc(width), IsUnsigned);
else else
@ -212,7 +212,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) & RHS, IsUnsigned); return APSInt(static_cast<const APInt&>(*this) & RHS, IsUnsigned);
} }
APSInt And(const APSInt& RHS) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APSInt& RHS) const {
return this->operator&(RHS); return this->operator&(RHS);
} }
@ -220,7 +220,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) | RHS, IsUnsigned); return APSInt(static_cast<const APInt&>(*this) | RHS, IsUnsigned);
} }
APSInt Or(const APSInt& RHS) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APSInt& RHS) const {
return this->operator|(RHS); return this->operator|(RHS);
} }
@ -229,7 +229,7 @@ public:
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
return APSInt(static_cast<const APInt&>(*this) ^ RHS, IsUnsigned); return APSInt(static_cast<const APInt&>(*this) ^ RHS, IsUnsigned);
} }
APSInt Xor(const APSInt& RHS) const { APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APSInt& RHS) const {
return this->operator^(RHS); return this->operator^(RHS);
} }

View File

@ -6684,9 +6684,9 @@ static const APInt gcd(const SCEVConstant *C1, const SCEVConstant *C2) {
uint32_t BBW = B.getBitWidth(); uint32_t BBW = B.getBitWidth();
if (ABW > BBW) if (ABW > BBW)
B.zext(ABW); B = B.zext(ABW);
else if (ABW < BBW) else if (ABW < BBW)
A.zext(BBW); A = A.zext(BBW);
return APIntOps::GreatestCommonDivisor(A, B); return APIntOps::GreatestCommonDivisor(A, B);
} }
@ -6698,9 +6698,9 @@ static const APInt srem(const SCEVConstant *C1, const SCEVConstant *C2) {
uint32_t BBW = B.getBitWidth(); uint32_t BBW = B.getBitWidth();
if (ABW > BBW) if (ABW > BBW)
B.sext(ABW); B = B.sext(ABW);
else if (ABW < BBW) else if (ABW < BBW)
A.sext(BBW); A = A.sext(BBW);
return APIntOps::srem(A, B); return APIntOps::srem(A, B);
} }
@ -6712,9 +6712,9 @@ static const APInt sdiv(const SCEVConstant *C1, const SCEVConstant *C2) {
uint32_t BBW = B.getBitWidth(); uint32_t BBW = B.getBitWidth();
if (ABW > BBW) if (ABW > BBW)
B.sext(ABW); B = B.sext(ABW);
else if (ABW < BBW) else if (ABW < BBW)
A.sext(BBW); A = A.sext(BBW);
return APIntOps::sdiv(A, B); return APIntOps::sdiv(A, B);
} }