From 65a4945bbd2b66138597e7710271090a8f2dc716 Mon Sep 17 00:00:00 2001 From: Hubert Tong Date: Tue, 20 Oct 2020 20:50:38 -0400 Subject: [PATCH] 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 --- lib/CodeGen/StackMaps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CodeGen/StackMaps.cpp b/lib/CodeGen/StackMaps.cpp index f7fb2e824bb..ee1a4a47b4c 100644 --- a/lib/CodeGen/StackMaps.cpp +++ b/lib/CodeGen/StackMaps.cpp @@ -401,7 +401,7 @@ void StackMaps::parseStatepointOpers(const MachineInstr &MI, SmallVector GCPtrIndices; unsigned GCPtrIdx = (unsigned)SO.getFirstGCPtrIdx(); assert((int)GCPtrIdx != -1); - assert(MOI - MI.operands_begin() == GCPtrIdx); + assert(MOI - MI.operands_begin() == GCPtrIdx + 0LL); while (NumGCPointers--) { GCPtrIndices.push_back(GCPtrIdx); GCPtrIdx = StackMaps::getNextMetaArgIdx(&MI, GCPtrIdx);