Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/llvm/ADT/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions include/llvm/CodeGen/SelectionDAGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ class SDValue {
template<> struct DenseMapInfo<SDValue> {
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) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Support/LEB128.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ static void emitSignedInt64(SmallVectorImpl<uint64_t> &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,
Expand Down Expand Up @@ -1437,7 +1437,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
continue;
}
const Constant *C = cast<Constant>(V);
unsigned Code = -1U;
unsigned Code = ~0U;
unsigned AbbrevToUse = 0;
if (C->isNullValue()) {
Code = bitc::CST_CODE_NULL;
Expand Down
6 changes: 3 additions & 3 deletions lib/DXIL/DxilUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Support/APFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion lib/Support/DataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/IPO/DeadArgumentElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions tools/clang/lib/Lex/LiteralSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -245,7 +249,7 @@ void clang::expandUCNs(SmallVectorImpl<char> &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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarDecl>(decl)) {
if (var->hasAttr<BlocksAttr>())
kind = 0; // __block
Expand All @@ -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;
}
Expand Down
Loading