Skip to content

Commit 5aec1ec

Browse files
authored
[NFC] Address compiler warnings: C4146 - Cases where we can swap to using ~ operator (microsoft#7551)
Addresses microsoft#7550.
1 parent d43d909 commit 5aec1ec

13 files changed

Lines changed: 33 additions & 28 deletions

File tree

include/llvm/ADT/StringExtras.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ static inline StringRef toStringRef(bool B) {
3636
/// Interpret the given character \p C as a hexadecimal digit and return its
3737
/// value.
3838
///
39-
/// If \p C is not a valid hex digit, -1U is returned.
39+
/// If \p C is not a valid hex digit, ~0U is returned.
4040
static inline unsigned hexDigitValue(char C) {
4141
if (C >= '0' && C <= '9') return C-'0';
4242
if (C >= 'a' && C <= 'f') return C-'a'+10U;
4343
if (C >= 'A' && C <= 'F') return C-'A'+10U;
44-
return -1U;
44+
return ~0U;
4545
}
4646

4747
/// utohex_buffer - Emit the specified number into the buffer specified by

include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ class SDValue {
191191
template<> struct DenseMapInfo<SDValue> {
192192
static inline SDValue getEmptyKey() {
193193
SDValue V;
194-
V.ResNo = -1U;
194+
V.ResNo = ~0U;
195195
return V;
196196
}
197197
static inline SDValue getTombstoneKey() {
198198
SDValue V;
199-
V.ResNo = -2U;
199+
V.ResNo = ~1U;
200200
return V;
201201
}
202202
static unsigned getHashValue(const SDValue &Val) {
@@ -879,7 +879,7 @@ inline SDValue::SDValue(SDNode *node, unsigned resno)
879879
: Node(node), ResNo(resno) {
880880
assert((!Node || ResNo < Node->getNumValues()) &&
881881
"Invalid result number for the given node!");
882-
assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
882+
assert(ResNo < ~1U && "Cannot use result numbers reserved for DenseMaps.");
883883
}
884884

885885
inline unsigned SDValue::getOpcode() const {

include/llvm/DebugInfo/DWARF/DWARFDebugRangeList.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class DWARFDebugRangeList {
4949
bool isBaseAddressSelectionEntry(uint8_t AddressSize) const {
5050
assert(AddressSize == 4 || AddressSize == 8);
5151
if (AddressSize == 4)
52-
return StartAddress == -1U;
52+
return StartAddress == ~0U;
5353
else
54-
return StartAddress == -1ULL;
54+
return StartAddress == ~0ULL;
5555
}
5656
};
5757

include/llvm/Support/LEB128.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr) {
103103
} while (Byte >= 128);
104104
// Sign extend negative numbers.
105105
if (Byte & 0x40)
106-
Value |= (-1ULL) << Shift;
106+
Value |= (~0ULL) << Shift;
107107
if (n)
108108
*n = (unsigned)(p - orig_p);
109109
return Value;

lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) {
24012401
if ((V & 1) == 0)
24022402
return V >> 1;
24032403
if (V != 1)
2404-
return -(V >> 1);
2404+
return ~(V >> 1) + 1;
24052405
// There is no such thing as -0 with integers. "-0" really means MININT.
24062406
return 1ULL << 63;
24072407
}

lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ static void emitSignedInt64(SmallVectorImpl<uint64_t> &Vals, uint64_t V) {
13601360
if ((int64_t)V >= 0)
13611361
Vals.push_back(V << 1);
13621362
else
1363-
Vals.push_back((-V << 1) | 1);
1363+
Vals.push_back(((~V + 1) << 1) | 1);
13641364
}
13651365

13661366
static void WriteConstants(unsigned FirstVal, unsigned LastVal,
@@ -1437,7 +1437,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
14371437
continue;
14381438
}
14391439
const Constant *C = cast<Constant>(V);
1440-
unsigned Code = -1U;
1440+
unsigned Code = ~0U;
14411441
unsigned AbbrevToUse = 0;
14421442
if (C->isNullValue()) {
14431443
Code = bitc::CST_CODE_NULL;

lib/DXIL/DxilUtil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ void PrintUnescapedString(StringRef Name, raw_ostream &Out) {
181181
if (C == '\\') {
182182
C = Name[++i];
183183
unsigned value = hexDigitValue(C);
184-
if (value != -1U) {
184+
if (value != ~0U) {
185185
C = (unsigned char)value;
186186
unsigned value2 = hexDigitValue(Name[i + 1]);
187-
assert(value2 != -1U && "otherwise, not a two digit hex escape");
188-
if (value2 != -1U) {
187+
assert(value2 != ~0U && "otherwise, not a two digit hex escape");
188+
if (value2 != ~0U) {
189189
C = (C << 4) + (unsigned char)value2;
190190
++i;
191191
}

lib/Support/APFloat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end,
331331

332332
/* If we ran off the end it is exactly zero or one-half, otherwise
333333
a little more. */
334-
if (hexDigit == -1U)
334+
if (hexDigit == ~0U)
335335
return digitValue == 0 ? lfExactlyZero: lfExactlyHalf;
336336
else
337337
return digitValue == 0 ? lfLessThanHalf: lfMoreThanHalf;
@@ -2368,7 +2368,7 @@ APFloat::convertFromHexadecimalString(StringRef s, roundingMode rounding_mode)
23682368
}
23692369

23702370
hex_value = hexDigitValue(*p);
2371-
if (hex_value == -1U)
2371+
if (hex_value == ~0U)
23722372
break;
23732373

23742374
p++;

lib/Support/DataExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const {
168168

169169
// Sign bit of byte is 2nd high order bit (0x40)
170170
if (shift < 64 && (byte & 0x40))
171-
result |= -(1ULL << shift);
171+
result |= (~(1ULL << shift) + 1);
172172

173173
*offset_ptr = offset;
174174
return result;

lib/Transforms/IPO/DeadArgumentElimination.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace {
146146
private:
147147
Liveness MarkIfNotLive(RetOrArg Use, UseVector &MaybeLiveUses);
148148
Liveness SurveyUse(const Use *U, UseVector &MaybeLiveUses,
149-
unsigned RetValNum = -1U);
149+
unsigned RetValNum = ~0U);
150150
Liveness SurveyUses(const Value *V, UseVector &MaybeLiveUses);
151151

152152
void SurveyFunction(const Function &F);
@@ -442,7 +442,7 @@ DAE::Liveness DAE::SurveyUse(const Use *U,
442442
// that U is really a use of an insertvalue instruction that uses the
443443
// original Use.
444444
const Function *F = RI->getParent()->getParent();
445-
if (RetValNum != -1U) {
445+
if (RetValNum != ~0U) {
446446
RetOrArg Use = CreateRet(F, RetValNum);
447447
// We might be live, depending on the liveness of Use.
448448
return MarkIfNotLive(Use, MaybeLiveUses);

0 commit comments

Comments
 (0)