[PATCH] D94417: [ADT][Support] Fix C4146 error from MSVC
Vladislav Vinogradov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 12 07:32:22 PST 2021
vinograd47 updated this revision to Diff 316087.
vinograd47 retitled this revision from "[ADT][Support] Disable C4146 MSVC warning" to "[ADT][Support] Fix C4146 error from MSVC".
vinograd47 edited the summary of this revision.
vinograd47 added a comment.
Reworked the patch. Fixed the warning instead of disabling it.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94417/new/
https://reviews.llvm.org/D94417
Files:
llvm/include/llvm/ADT/StringExtras.h
llvm/include/llvm/Support/MathExtras.h
Index: llvm/include/llvm/Support/MathExtras.h
===================================================================
--- llvm/include/llvm/Support/MathExtras.h
+++ llvm/include/llvm/Support/MathExtras.h
@@ -440,7 +440,7 @@
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.
Index: llvm/include/llvm/ADT/StringExtras.h
===================================================================
--- llvm/include/llvm/ADT/StringExtras.h
+++ llvm/include/llvm/ADT/StringExtras.h
@@ -71,7 +71,7 @@
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 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 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 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));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94417.316087.patch
Type: text/x-patch
Size: 1887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210112/005fae6c/attachment.bin>
More information about the llvm-commits
mailing list