[PATCH] D91968: llvm/ADT/StringExtras.h hexDigitValue - Init of integer buffer

Jerker B├Ąck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 23 13:38:19 PST 2020


jerker.back updated this revision to Diff 307191.
jerker.back added a comment.

Expanding the patch to similar code places in the file. 
Compiler warnings are gone under -Wall


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91968/new/

https://reviews.llvm.org/D91968

Files:
  llvm/include/llvm/ADT/StringExtras.h


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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91968.307191.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201123/409bbad6/attachment.bin>


More information about the llvm-commits mailing list