Skip to content

Commit 36606cf

Browse files
committed
[NFC] Replace -1U{LL} expressions with appropriate *_MAX macros in Support library.
This makes a code a bit more clear and also gets rid of C4146 warning on MSVC compiler: 'unary minus operator applied to unsigned type, result still unsigned'. In case uint64_t variable is initialized or compared against -1U expression, which corresponds to 32-bit constant, UINT_MAX macro is used to preserve NFC semantics; -1ULL is replaced with UINT64_MAX. Reviewed By: dblaikie, craig.topper Differential Revision: https://reviews.llvm.org/D143942
1 parent 31c3528 commit 36606cf

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

llvm/include/llvm/Support/BlockFrequency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BlockFrequency {
2727
BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
2828

2929
/// Returns the maximum possible frequency, the saturation value.
30-
static uint64_t getMaxFrequency() { return -1ULL; }
30+
static uint64_t getMaxFrequency() { return UINT64_MAX; }
3131

3232
/// Returns the frequency as a fixpoint number scaled by the entry
3333
/// frequency.

llvm/include/llvm/Support/LEB128.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
191191
} while (Byte >= 128);
192192
// Sign extend negative numbers if needed.
193193
if (Shift < 64 && (Byte & 0x40))
194-
Value |= (-1ULL) << Shift;
194+
Value |= UINT64_MAX << Shift;
195195
if (n)
196196
*n = (unsigned)(p - orig_p);
197197
return Value;

llvm/lib/Support/APFloat.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end,
568568

569569
/* If we ran off the end it is exactly zero or one-half, otherwise
570570
a little more. */
571-
if (hexDigit == -1U)
571+
if (hexDigit == UINT_MAX)
572572
return digitValue == 0 ? lfExactlyZero: lfExactlyHalf;
573573
else
574574
return digitValue == 0 ? lfLessThanHalf: lfMoreThanHalf;
@@ -585,7 +585,7 @@ lostFractionThroughTruncation(const APFloatBase::integerPart *parts,
585585

586586
lsb = APInt::tcLSB(parts, partCount);
587587

588-
/* Note this is guaranteed true if bits == 0, or LSB == -1U. */
588+
/* Note this is guaranteed true if bits == 0, or LSB == UINT_MAX. */
589589
if (bits <= lsb)
590590
return lfExactlyZero;
591591
if (bits == lsb + 1)
@@ -2815,7 +2815,7 @@ IEEEFloat::convertFromHexadecimalString(StringRef s,
28152815
}
28162816

28172817
hex_value = hexDigitValue(*p);
2818-
if (hex_value == -1U)
2818+
if (hex_value == UINT_MAX)
28192819
break;
28202820

28212821
p++;

llvm/lib/Support/APInt.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ inline static unsigned getDigit(char cdigit, uint8_t radix) {
6868
if (r < radix)
6969
return r;
7070

71-
return -1U;
71+
return UINT_MAX;
7272
}
7373

7474

@@ -2330,7 +2330,7 @@ void APInt::tcClearBit(WordType *parts, unsigned bit) {
23302330
}
23312331

23322332
/// Returns the bit number of the least significant set bit of a number. If the
2333-
/// input number has no bits set -1U is returned.
2333+
/// input number has no bits set UINT_MAX is returned.
23342334
unsigned APInt::tcLSB(const WordType *parts, unsigned n) {
23352335
for (unsigned i = 0; i < n; i++) {
23362336
if (parts[i] != 0) {
@@ -2339,11 +2339,11 @@ unsigned APInt::tcLSB(const WordType *parts, unsigned n) {
23392339
}
23402340
}
23412341

2342-
return -1U;
2342+
return UINT_MAX;
23432343
}
23442344

23452345
/// Returns the bit number of the most significant set bit of a number.
2346-
/// If the input number has no bits set -1U is returned.
2346+
/// If the input number has no bits set UINT_MAX is returned.
23472347
unsigned APInt::tcMSB(const WordType *parts, unsigned n) {
23482348
do {
23492349
--n;
@@ -2356,7 +2356,7 @@ unsigned APInt::tcMSB(const WordType *parts, unsigned n) {
23562356
}
23572357
} while (n);
23582358

2359-
return -1U;
2359+
return UINT_MAX;
23602360
}
23612361

23622362
/// Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to

0 commit comments

Comments
 (0)