forked from OSchip/llvm-project
[ADT][Support] Fix C4146 error from MSVC
Unary minus operator applied to unsigned type, result still unsigned. Use `~0U` instead of `-1U` and `1 + ~VAL` instead of `-VAL`. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D94417
This commit is contained in:
parent
aa8a2d8a3d
commit
76f5c5a7b0
|
@ -71,7 +71,7 @@ inline unsigned hexDigitValue(char C) {
|
|||
constexpr HexTable() {
|
||||
// Default initialize everything to invalid.
|
||||
for (int i = 0; i < 255; ++i)
|
||||
LUT[i] = -1U;
|
||||
LUT[i] = ~0U;
|
||||
// Initialize `0`-`9`.
|
||||
for (int i = 0; i < 10; ++i)
|
||||
LUT['0' + i] = i;
|
||||
|
@ -88,7 +88,7 @@ inline unsigned hexDigitValue(char C) {
|
|||
inline bool isDigit(char C) { return C >= '0' && C <= '9'; }
|
||||
|
||||
/// Checks if character \p C is a hexadecimal numeric character.
|
||||
inline bool isHexDigit(char C) { return hexDigitValue(C) != -1U; }
|
||||
inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; }
|
||||
|
||||
/// Checks if character \p C is a valid letter as classified by "C" locale.
|
||||
inline bool isAlpha(char C) {
|
||||
|
@ -184,7 +184,7 @@ inline std::string toHex(ArrayRef<uint8_t> Input, bool LowerCase = false) {
|
|||
inline bool tryGetHexFromNibbles(char MSB, char LSB, uint8_t &Hex) {
|
||||
unsigned U1 = hexDigitValue(MSB);
|
||||
unsigned U2 = hexDigitValue(LSB);
|
||||
if (U1 == -1U || U2 == -1U)
|
||||
if (U1 == ~0U || U2 == ~0U)
|
||||
return false;
|
||||
|
||||
Hex = static_cast<uint8_t>((U1 << 4) | U2);
|
||||
|
@ -291,7 +291,7 @@ inline std::string utostr(uint64_t X, bool isNeg = false) {
|
|||
|
||||
inline std::string itostr(int64_t X) {
|
||||
if (X < 0)
|
||||
return utostr(-static_cast<uint64_t>(X), true);
|
||||
return utostr(static_cast<uint64_t>(1) + ~static_cast<uint64_t>(X), true);
|
||||
else
|
||||
return utostr(static_cast<uint64_t>(X));
|
||||
}
|
||||
|
|
|
@ -440,7 +440,7 @@ inline uint64_t maxUIntN(uint64_t N) {
|
|||
inline int64_t minIntN(int64_t N) {
|
||||
assert(N > 0 && N <= 64 && "integer width out of range");
|
||||
|
||||
return -(UINT64_C(1)<<(N-1));
|
||||
return UINT64_C(1) + ~(UINT64_C(1) << (N - 1));
|
||||
}
|
||||
|
||||
/// Gets the maximum value for a N-bit signed integer.
|
||||
|
|
Loading…
Reference in New Issue