[PATCH] D89612: NFC: Fix -Wsign-compare warnings on 32-bit builds
Hubert Tong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 16 20:29:46 PDT 2020
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: dantrushin, hokein, daltenty, stevewan, jasonliu.
Herald added a subscriber: hiraditya.
Herald added projects: clang, LLVM.
hubert.reinterpretcast requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89612
Files:
clang/lib/Serialization/ASTReaderStmt.cpp
llvm/lib/CodeGen/StackMaps.cpp
Index: llvm/lib/CodeGen/StackMaps.cpp
===================================================================
--- llvm/lib/CodeGen/StackMaps.cpp
+++ llvm/lib/CodeGen/StackMaps.cpp
@@ -401,7 +401,7 @@
SmallVector<unsigned, 8> 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);
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2186,9 +2186,9 @@
unsigned NumArgs = Record.readInt();
E->BeginLoc = readSourceLocation();
E->EndLoc = readSourceLocation();
- assert(
- (NumArgs == std::distance(E->children().begin(), E->children().end())) &&
- "Wrong NumArgs!");
+ assert((NumArgs + 0LL ==
+ std::distance(E->children().begin(), E->children().end())) &&
+ "Wrong NumArgs!");
(void)NumArgs;
for (Stmt *&Child : E->children())
Child = Record.readSubStmt();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89612.298798.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201017/144ad93e/attachment.bin>
More information about the llvm-commits
mailing list