diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index 270989b349..684ee0f9dc 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -36,12 +36,12 @@ static inline StringRef toStringRef(bool B) { /// Interpret the given character \p C as a hexadecimal digit and return its /// value. /// -/// If \p C is not a valid hex digit, -1U is returned. +/// If \p C is not a valid hex digit, ~0U is returned. static inline unsigned hexDigitValue(char C) { if (C >= '0' && C <= '9') return C-'0'; if (C >= 'a' && C <= 'f') return C-'a'+10U; if (C >= 'A' && C <= 'F') return C-'A'+10U; - return -1U; + return ~0U; } /// utohex_buffer - Emit the specified number into the buffer specified by diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index d4a6371216..ba63d80e94 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -191,12 +191,12 @@ class SDValue { template<> struct DenseMapInfo { static inline SDValue getEmptyKey() { SDValue V; - V.ResNo = -1U; + V.ResNo = ~0U; return V; } static inline SDValue getTombstoneKey() { SDValue V; - V.ResNo = -2U; + V.ResNo = ~1U; return V; } static unsigned getHashValue(const SDValue &Val) { @@ -879,7 +879,7 @@ inline SDValue::SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) { assert((!Node || ResNo < Node->getNumValues()) && "Invalid result number for the given node!"); - assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps."); + assert(ResNo < ~1U && "Cannot use result numbers reserved for DenseMaps."); } inline unsigned SDValue::getOpcode() const { diff --git a/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h b/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h index c930bd603d..8eea252b60 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h +++ b/include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h @@ -49,9 +49,9 @@ class DWARFDebugRangeList { bool isBaseAddressSelectionEntry(uint8_t AddressSize) const { assert(AddressSize == 4 || AddressSize == 8); if (AddressSize == 4) - return StartAddress == -1U; + return StartAddress == ~0U; else - return StartAddress == -1ULL; + return StartAddress == ~0ULL; } }; diff --git a/include/llvm/Support/LEB128.h b/include/llvm/Support/LEB128.h index 1324cb82ca..f8a2843412 100644 --- a/include/llvm/Support/LEB128.h +++ b/include/llvm/Support/LEB128.h @@ -103,7 +103,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr) { } while (Byte >= 128); // Sign extend negative numbers. if (Byte & 0x40) - Value |= (-1ULL) << Shift; + Value |= (~0ULL) << Shift; if (n) *n = (unsigned)(p - orig_p); return Value; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 185c291d66..a87128ca26 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2401,7 +2401,7 @@ uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) { if ((V & 1) == 0) return V >> 1; if (V != 1) - return -(V >> 1); + return ~(V >> 1) + 1; // There is no such thing as -0 with integers. "-0" really means MININT. return 1ULL << 63; } diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 0718c81451..f02344ae64 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1360,7 +1360,7 @@ static void emitSignedInt64(SmallVectorImpl &Vals, uint64_t V) { if ((int64_t)V >= 0) Vals.push_back(V << 1); else - Vals.push_back((-V << 1) | 1); + Vals.push_back(((~V + 1) << 1) | 1); } static void WriteConstants(unsigned FirstVal, unsigned LastVal, @@ -1437,7 +1437,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, continue; } const Constant *C = cast(V); - unsigned Code = -1U; + unsigned Code = ~0U; unsigned AbbrevToUse = 0; if (C->isNullValue()) { Code = bitc::CST_CODE_NULL; diff --git a/lib/DXIL/DxilUtil.cpp b/lib/DXIL/DxilUtil.cpp index 966c2e189c..cc0b509772 100644 --- a/lib/DXIL/DxilUtil.cpp +++ b/lib/DXIL/DxilUtil.cpp @@ -181,11 +181,11 @@ void PrintUnescapedString(StringRef Name, raw_ostream &Out) { if (C == '\\') { C = Name[++i]; unsigned value = hexDigitValue(C); - if (value != -1U) { + if (value != ~0U) { C = (unsigned char)value; unsigned value2 = hexDigitValue(Name[i + 1]); - assert(value2 != -1U && "otherwise, not a two digit hex escape"); - if (value2 != -1U) { + assert(value2 != ~0U && "otherwise, not a two digit hex escape"); + if (value2 != ~0U) { C = (C << 4) + (unsigned char)value2; ++i; } diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index 3c76c72271..f8f1fb03cd 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -331,7 +331,7 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, /* If we ran off the end it is exactly zero or one-half, otherwise a little more. */ - if (hexDigit == -1U) + if (hexDigit == ~0U) return digitValue == 0 ? lfExactlyZero: lfExactlyHalf; else return digitValue == 0 ? lfLessThanHalf: lfMoreThanHalf; @@ -2368,7 +2368,7 @@ APFloat::convertFromHexadecimalString(StringRef s, roundingMode rounding_mode) } hex_value = hexDigitValue(*p); - if (hex_value == -1U) + if (hex_value == ~0U) break; p++; diff --git a/lib/Support/DataExtractor.cpp b/lib/Support/DataExtractor.cpp index 5d6d60a87f..625fb3595a 100644 --- a/lib/Support/DataExtractor.cpp +++ b/lib/Support/DataExtractor.cpp @@ -168,7 +168,7 @@ int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const { // Sign bit of byte is 2nd high order bit (0x40) if (shift < 64 && (byte & 0x40)) - result |= -(1ULL << shift); + result |= (~(1ULL << shift) + 1); *offset_ptr = offset; return result; diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index d044764025..0cf9f7797a 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -146,7 +146,7 @@ namespace { private: Liveness MarkIfNotLive(RetOrArg Use, UseVector &MaybeLiveUses); Liveness SurveyUse(const Use *U, UseVector &MaybeLiveUses, - unsigned RetValNum = -1U); + unsigned RetValNum = ~0U); Liveness SurveyUses(const Value *V, UseVector &MaybeLiveUses); void SurveyFunction(const Function &F); @@ -442,7 +442,7 @@ DAE::Liveness DAE::SurveyUse(const Use *U, // that U is really a use of an insertvalue instruction that uses the // original Use. const Function *F = RI->getParent()->getParent(); - if (RetValNum != -1U) { + if (RetValNum != ~0U) { RetOrArg Use = CreateRet(F, RetValNum); // We might be live, depending on the liveness of Use. return MarkIfNotLive(Use, MaybeLiveUses); diff --git a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 2d28b14213..66e01198bd 100644 --- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -998,7 +998,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, for (unsigned i = 0; i < VWidth; i++) { if (DemandedElts[i]) { unsigned MaskVal = Shuffle->getMaskValue(i); - if (MaskVal != -1u) { + if (MaskVal != ~0u) { assert(MaskVal < LHSVWidth * 2 && "shufflevector mask index out of range!"); if (MaskVal < LHSVWidth) @@ -1022,7 +1022,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, bool NewUndefElts = false; for (unsigned i = 0; i < VWidth; i++) { unsigned MaskVal = Shuffle->getMaskValue(i); - if (MaskVal == -1u) { + if (MaskVal == ~0u) { UndefElts.setBit(i); } else if (!DemandedElts[i]) { NewUndefElts = true; diff --git a/tools/clang/lib/Lex/LiteralSupport.cpp b/tools/clang/lib/Lex/LiteralSupport.cpp index 606c821bb2..62f241812b 100644 --- a/tools/clang/lib/Lex/LiteralSupport.cpp +++ b/tools/clang/lib/Lex/LiteralSupport.cpp @@ -141,8 +141,12 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin, // Hex escapes are a maximal series of hex digits. bool Overflow = false; for (; ThisTokBuf != ThisTokEnd; ++ThisTokBuf) { - int CharVal = llvm::hexDigitValue(ThisTokBuf[0]); - if (CharVal == -1) break; + // originally returned -1 for invalid hex digits, now returns ~0u + // signature: static inline unsigned int llvm::hexDigitValue(char C) + unsigned int CharVal = llvm::hexDigitValue(ThisTokBuf[0]); + if (CharVal == ~0U) + break; + // About to shift out a digit? if (ResultChar & 0xF0000000) Overflow = true; @@ -245,7 +249,7 @@ void clang::expandUCNs(SmallVectorImpl &Buf, StringRef Input) { uint32_t CodePoint = 0; for (++I; NumHexDigits != 0; ++I, --NumHexDigits) { unsigned Value = llvm::hexDigitValue(*I); - assert(Value != -1U); + assert(Value != ~0U); CodePoint <<= 4; CodePoint += Value; @@ -278,8 +282,9 @@ static bool ProcessUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8); unsigned short UcnLenSave = UcnLen; for (; ThisTokBuf != ThisTokEnd && UcnLenSave; ++ThisTokBuf, UcnLenSave--) { - int CharVal = llvm::hexDigitValue(ThisTokBuf[0]); - if (CharVal == -1) break; + unsigned int CharVal = llvm::hexDigitValue(ThisTokBuf[0]); + if (CharVal == ~0U) + break; UcnVal <<= 4; UcnVal |= CharVal; } diff --git a/tools/clang/lib/Sema/SemaDecl.cpp b/tools/clang/lib/Sema/SemaDecl.cpp index e09bf4623c..a772054960 100644 --- a/tools/clang/lib/Sema/SemaDecl.cpp +++ b/tools/clang/lib/Sema/SemaDecl.cpp @@ -5331,7 +5331,7 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) { Qualifiers::ObjCLifetime lifetime = type.getObjCLifetime(); if (lifetime == Qualifiers::OCL_Autoreleasing) { // Various kinds of declaration aren't allowed to be __autoreleasing. - unsigned kind = -1U; + unsigned kind = ~0U; if (VarDecl *var = dyn_cast(decl)) { if (var->hasAttr()) kind = 0; // __block @@ -5343,7 +5343,7 @@ bool Sema::inferObjCARCLifetime(ValueDecl *decl) { kind = 2; // field } - if (kind != -1U) { + if (kind != ~0U) { Diag(decl->getLocation(), diag::err_arc_autoreleasing_var) << kind; }