Skip to content

Commit 134ffa8

Browse files
NFC: Fix -Wsign-compare warnings on 32-bit builds
Comparing 32-bit `ptrdiff_t` against 32-bit `unsigned` results in `-Wsign-compare` warnings for both GCC and Clang. The warning for the cases in question appear to identify an issue where the `ptrdiff_t` value would be mutated via conversion to an unsigned type. The warning is resolved by using the usual arithmetic conversions to safely preserve the value of the `unsigned` operand while trying to convert to a signed type. Host platforms where `unsigned` has the same width as `unsigned long long` will need to make a different change, but using an explicit cast has disadvantages that can be avoided for now. Reviewed By: dantrushin Differential Revision: https://reviews.llvm.org/D89612
1 parent 15e772e commit 134ffa8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,9 +2186,9 @@ void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) {
21862186
unsigned NumArgs = Record.readInt();
21872187
E->BeginLoc = readSourceLocation();
21882188
E->EndLoc = readSourceLocation();
2189-
assert(
2190-
(NumArgs == std::distance(E->children().begin(), E->children().end())) &&
2191-
"Wrong NumArgs!");
2189+
assert((NumArgs + 0LL ==
2190+
std::distance(E->children().begin(), E->children().end())) &&
2191+
"Wrong NumArgs!");
21922192
(void)NumArgs;
21932193
for (Stmt *&Child : E->children())
21942194
Child = Record.readSubStmt();

llvm/lib/CodeGen/StackMaps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void StackMaps::parseStatepointOpers(const MachineInstr &MI,
401401
SmallVector<unsigned, 8> GCPtrIndices;
402402
unsigned GCPtrIdx = (unsigned)SO.getFirstGCPtrIdx();
403403
assert((int)GCPtrIdx != -1);
404-
assert(MOI - MI.operands_begin() == GCPtrIdx);
404+
assert(MOI - MI.operands_begin() == GCPtrIdx + 0LL);
405405
while (NumGCPointers--) {
406406
GCPtrIndices.push_back(GCPtrIdx);
407407
GCPtrIdx = StackMaps::getNextMetaArgIdx(&MI, GCPtrIdx);

0 commit comments

Comments
 (0)