<div dir="ltr">Here as well, I think LLVM_NODISCARD is inappropriate. A function can return an int without having its value checked, so why not an APInt?</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Oct 14, 2016 at 5:31 PM Justin Bogner via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: bogner<br class="gmail_msg">
Date: Fri Oct 14 19:22:06 2016<br class="gmail_msg">
New Revision: 284297<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284297&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=284297&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
ADT: Use LLVM_NODISCARD instead of LLVM_ATTRIBUTE_UNUSED_RESULT for APInt<br class="gmail_msg">
<br class="gmail_msg">
Instead of annotating (most of) the APInt API, we can just annotate<br class="gmail_msg">
the type directly. This is less code and it will warn in more cases.<br class="gmail_msg">
<br class="gmail_msg">
Modified:<br class="gmail_msg">
llvm/trunk/include/llvm/ADT/APInt.h<br class="gmail_msg">
llvm/trunk/include/llvm/ADT/APSInt.h<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/ADT/APInt.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=284297&r1=284296&r2=284297&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=284297&r1=284296&r2=284297&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/ADT/APInt.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/ADT/APInt.h Fri Oct 14 19:22:06 2016<br class="gmail_msg">
@@ -74,7 +74,7 @@ inline APInt operator-(APInt);<br class="gmail_msg">
/// * In general, the class tries to follow the style of computation that LLVM<br class="gmail_msg">
/// uses in its IR. This simplifies its use for LLVM.<br class="gmail_msg">
///<br class="gmail_msg">
-class APInt {<br class="gmail_msg">
+class LLVM_NODISCARD APInt {<br class="gmail_msg">
unsigned BitWidth; ///< The number of bits in this APInt.<br class="gmail_msg">
<br class="gmail_msg">
/// This union is used to store the integer value. When the<br class="gmail_msg">
@@ -777,9 +777,7 @@ public:<br class="gmail_msg">
return APInt(getBitWidth(), VAL & RHS.VAL);<br class="gmail_msg">
return AndSlowCase(RHS);<br class="gmail_msg">
}<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APInt &RHS) const {<br class="gmail_msg">
- return this->operator&(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APInt And(const APInt &RHS) const { return this->operator&(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Bitwise OR operator.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -799,9 +797,7 @@ public:<br class="gmail_msg">
/// calling operator|.<br class="gmail_msg">
///<br class="gmail_msg">
/// \returns An APInt value representing the bitwise OR of *this and RHS.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APInt &RHS) const {<br class="gmail_msg">
- return this->operator|(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APInt Or(const APInt &RHS) const { return this->operator|(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Bitwise XOR operator.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -821,9 +817,7 @@ public:<br class="gmail_msg">
/// through the usage of operator^.<br class="gmail_msg">
///<br class="gmail_msg">
/// \returns An APInt value representing the bitwise XOR of *this and RHS.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APInt &RHS) const {<br class="gmail_msg">
- return this->operator^(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APInt Xor(const APInt &RHS) const { return this->operator^(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Multiplication operator.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -843,17 +837,17 @@ public:<br class="gmail_msg">
/// \brief Arithmetic right-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Arithmetic right-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const;<br class="gmail_msg">
+ APInt ashr(unsigned shiftAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Logical right-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Logical right-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const;<br class="gmail_msg">
+ APInt lshr(unsigned shiftAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Left-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Left-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const {<br class="gmail_msg">
+ APInt shl(unsigned shiftAmt) const {<br class="gmail_msg">
assert(shiftAmt <= BitWidth && "Invalid shift amount");<br class="gmail_msg">
if (isSingleWord()) {<br class="gmail_msg">
if (shiftAmt >= BitWidth)<br class="gmail_msg">
@@ -864,31 +858,31 @@ public:<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Rotate left by rotateAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(unsigned rotateAmt) const;<br class="gmail_msg">
+ APInt rotl(unsigned rotateAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Rotate right by rotateAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(unsigned rotateAmt) const;<br class="gmail_msg">
+ APInt rotr(unsigned rotateAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Arithmetic right-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Arithmetic right-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(const APInt &shiftAmt) const;<br class="gmail_msg">
+ APInt ashr(const APInt &shiftAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Logical right-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Logical right-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(const APInt &shiftAmt) const;<br class="gmail_msg">
+ APInt lshr(const APInt &shiftAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Left-shift function.<br class="gmail_msg">
///<br class="gmail_msg">
/// Left-shift this APInt by shiftAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(const APInt &shiftAmt) const;<br class="gmail_msg">
+ APInt shl(const APInt &shiftAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Rotate left by rotateAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotl(const APInt &rotateAmt) const;<br class="gmail_msg">
+ APInt rotl(const APInt &rotateAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Rotate right by rotateAmt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT rotr(const APInt &rotateAmt) const;<br class="gmail_msg">
+ APInt rotr(const APInt &rotateAmt) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Unsigned division operation.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -896,12 +890,12 @@ public:<br class="gmail_msg">
/// RHS are treated as unsigned quantities for purposes of this division.<br class="gmail_msg">
///<br class="gmail_msg">
/// \returns a new APInt value containing the division result<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const;<br class="gmail_msg">
+ APInt udiv(const APInt &RHS) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Signed division function for APInt.<br class="gmail_msg">
///<br class="gmail_msg">
/// Signed divide this APInt by APInt RHS.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const;<br class="gmail_msg">
+ APInt sdiv(const APInt &RHS) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Unsigned remainder operation.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -912,12 +906,12 @@ public:<br class="gmail_msg">
/// is *this.<br class="gmail_msg">
///<br class="gmail_msg">
/// \returns a new APInt value containing the remainder result<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const;<br class="gmail_msg">
+ APInt urem(const APInt &RHS) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Function for signed remainder operation.<br class="gmail_msg">
///<br class="gmail_msg">
/// Signed remainder operation on APInt.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const;<br class="gmail_msg">
+ APInt srem(const APInt &RHS) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Dual division/remainder interface.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -1160,7 +1154,7 @@ public:<br class="gmail_msg">
///<br class="gmail_msg">
/// Truncate the APInt to a specified width. It is an error to specify a width<br class="gmail_msg">
/// that is greater than or equal to the current width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const;<br class="gmail_msg">
+ APInt trunc(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Sign extend to a new width.<br class="gmail_msg">
///<br class="gmail_msg">
@@ -1168,38 +1162,38 @@ public:<br class="gmail_msg">
/// bit is set, the fill on the left will be done with 1 bits, otherwise zero.<br class="gmail_msg">
/// It is an error to specify a width that is less than or equal to the<br class="gmail_msg">
/// current width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT sext(unsigned width) const;<br class="gmail_msg">
+ APInt sext(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Zero extend to a new width.<br class="gmail_msg">
///<br class="gmail_msg">
/// This operation zero extends the APInt to a new width. The high order bits<br class="gmail_msg">
/// are filled with 0 bits. It is an error to specify a width that is less<br class="gmail_msg">
/// than or equal to the current width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const;<br class="gmail_msg">
+ APInt zext(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Sign extend or truncate to width<br class="gmail_msg">
///<br class="gmail_msg">
/// Make this APInt have the bit width given by \p width. The value is sign<br class="gmail_msg">
/// extended, truncated, or left alone to make it that width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrTrunc(unsigned width) const;<br class="gmail_msg">
+ APInt sextOrTrunc(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Zero extend or truncate to width<br class="gmail_msg">
///<br class="gmail_msg">
/// Make this APInt have the bit width given by \p width. The value is zero<br class="gmail_msg">
/// extended, truncated, or left alone to make it that width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const;<br class="gmail_msg">
+ APInt zextOrTrunc(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Sign extend or truncate to width<br class="gmail_msg">
///<br class="gmail_msg">
/// Make this APInt have the bit width given by \p width. The value is sign<br class="gmail_msg">
/// extended, or left alone to make it that width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT sextOrSelf(unsigned width) const;<br class="gmail_msg">
+ APInt sextOrSelf(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Zero extend or truncate to width<br class="gmail_msg">
///<br class="gmail_msg">
/// Make this APInt have the bit width given by \p width. The value is zero<br class="gmail_msg">
/// extended, or left alone to make it that width.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrSelf(unsigned width) const;<br class="gmail_msg">
+ APInt zextOrSelf(unsigned width) const;<br class="gmail_msg">
<br class="gmail_msg">
/// @}<br class="gmail_msg">
/// \name Bit Manipulation Operators<br class="gmail_msg">
@@ -1436,11 +1430,11 @@ public:<br class="gmail_msg">
std::string toString(unsigned Radix, bool Signed) const;<br class="gmail_msg">
<br class="gmail_msg">
/// \returns a byte-swapped representation of this APInt Value.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const;<br class="gmail_msg">
+ APInt byteSwap() const;<br class="gmail_msg">
<br class="gmail_msg">
/// \returns the value with the bit representation reversed of this APInt<br class="gmail_msg">
/// Value.<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT reverseBits() const;<br class="gmail_msg">
+ APInt reverseBits() const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Converts this APInt to a double value.<br class="gmail_msg">
double roundToDouble(bool isSigned) const;<br class="gmail_msg">
@@ -1483,7 +1477,7 @@ public:<br class="gmail_msg">
///<br class="gmail_msg">
/// The conversion does not do a translation from double to integer, it just<br class="gmail_msg">
/// re-interprets the bits of the double.<br class="gmail_msg">
- static APInt LLVM_ATTRIBUTE_UNUSED_RESULT doubleToBits(double V) {<br class="gmail_msg">
+ static APInt doubleToBits(double V) {<br class="gmail_msg">
union {<br class="gmail_msg">
uint64_t I;<br class="gmail_msg">
double D;<br class="gmail_msg">
@@ -1496,7 +1490,7 @@ public:<br class="gmail_msg">
///<br class="gmail_msg">
/// The conversion does not do a translation from float to integer, it just<br class="gmail_msg">
/// re-interprets the bits of the float.<br class="gmail_msg">
- static APInt LLVM_ATTRIBUTE_UNUSED_RESULT floatToBits(float V) {<br class="gmail_msg">
+ static APInt floatToBits(float V) {<br class="gmail_msg">
union {<br class="gmail_msg">
unsigned I;<br class="gmail_msg">
float F;<br class="gmail_msg">
@@ -1557,12 +1551,12 @@ public:<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Compute the square root<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT sqrt() const;<br class="gmail_msg">
+ APInt sqrt() const;<br class="gmail_msg">
<br class="gmail_msg">
/// \brief Get the absolute value;<br class="gmail_msg">
///<br class="gmail_msg">
/// If *this is < 0 then return -(*this), otherwise *this;<br class="gmail_msg">
- APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const {<br class="gmail_msg">
+ APInt abs() const {<br class="gmail_msg">
if (isNegative())<br class="gmail_msg">
return -(*this);<br class="gmail_msg">
return *this;<br class="gmail_msg">
<br class="gmail_msg">
Modified: llvm/trunk/include/llvm/ADT/APSInt.h<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=284297&r1=284296&r2=284297&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APSInt.h?rev=284297&r1=284296&r2=284297&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- llvm/trunk/include/llvm/ADT/APSInt.h (original)<br class="gmail_msg">
+++ llvm/trunk/include/llvm/ADT/APSInt.h Fri Oct 14 19:22:06 2016<br class="gmail_msg">
@@ -19,7 +19,7 @@<br class="gmail_msg">
<br class="gmail_msg">
namespace llvm {<br class="gmail_msg">
<br class="gmail_msg">
-class APSInt : public APInt {<br class="gmail_msg">
+class LLVM_NODISCARD APSInt : public APInt {<br class="gmail_msg">
bool IsUnsigned;<br class="gmail_msg">
<br class="gmail_msg">
public:<br class="gmail_msg">
@@ -78,22 +78,22 @@ public:<br class="gmail_msg">
return isSigned() ? getSExtValue() : getZExtValue();<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(uint32_t width) const {<br class="gmail_msg">
+ APSInt trunc(uint32_t width) const {<br class="gmail_msg">
return APSInt(APInt::trunc(width), IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extend(uint32_t width) const {<br class="gmail_msg">
+ APSInt extend(uint32_t width) const {<br class="gmail_msg">
if (IsUnsigned)<br class="gmail_msg">
return APSInt(zext(width), IsUnsigned);<br class="gmail_msg">
else<br class="gmail_msg">
return APSInt(sext(width), IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const {<br class="gmail_msg">
- if (IsUnsigned)<br class="gmail_msg">
- return APSInt(zextOrTrunc(width), IsUnsigned);<br class="gmail_msg">
- else<br class="gmail_msg">
- return APSInt(sextOrTrunc(width), IsUnsigned);<br class="gmail_msg">
+ APSInt extOrTrunc(uint32_t width) const {<br class="gmail_msg">
+ if (IsUnsigned)<br class="gmail_msg">
+ return APSInt(zextOrTrunc(width), IsUnsigned);<br class="gmail_msg">
+ else<br class="gmail_msg">
+ return APSInt(sextOrTrunc(width), IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
const APSInt &operator%=(const APSInt &RHS) {<br class="gmail_msg">
@@ -235,25 +235,19 @@ public:<br class="gmail_msg">
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");<br class="gmail_msg">
return APSInt(static_cast<const APInt&>(*this) & RHS, IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT And(const APSInt& RHS) const {<br class="gmail_msg">
- return this->operator&(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APSInt And(const APSInt &RHS) const { return this->operator&(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
APSInt operator|(const APSInt& RHS) const {<br class="gmail_msg">
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");<br class="gmail_msg">
return APSInt(static_cast<const APInt&>(*this) | RHS, IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Or(const APSInt& RHS) const {<br class="gmail_msg">
- return this->operator|(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APSInt Or(const APSInt &RHS) const { return this->operator|(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
APSInt operator^(const APSInt &RHS) const {<br class="gmail_msg">
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");<br class="gmail_msg">
return APSInt(static_cast<const APInt&>(*this) ^ RHS, IsUnsigned);<br class="gmail_msg">
}<br class="gmail_msg">
- APSInt LLVM_ATTRIBUTE_UNUSED_RESULT Xor(const APSInt& RHS) const {<br class="gmail_msg">
- return this->operator^(RHS);<br class="gmail_msg">
- }<br class="gmail_msg">
+ APSInt Xor(const APSInt &RHS) const { return this->operator^(RHS); }<br class="gmail_msg">
<br class="gmail_msg">
APSInt operator*(const APSInt& RHS) const {<br class="gmail_msg">
assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
llvm-commits mailing list<br class="gmail_msg">
<a href="mailto:llvm-commits@lists.llvm.org" class="gmail_msg" target="_blank">llvm-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="gmail_msg">
</blockquote></div>