[Mlir-commits] [mlir] [mlir][NFC] Fix some different sign comparison warnings (PR #234999)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Oct 23 08:48:03 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-memref
@llvm/pr-subscribers-mlir-core
Author: David Spickett (DavidSpickett)
<details>
<summary>Changes</summary>
I saw these doing a build on Arm 32-bit, but I don't think they're specific to it.
* OperationSupport.h: std::distance returns a signed type but kSmallAttributeList is unsigned. I assume first is always before last, so it's safe to cast std::distance to size_t.
* In MemRefOps.cpp: srcStaticCount is created using llvm::count_if, but the type is changed. Then later compared to another llvm::count_if. Fixed that by using auto to keep the same type.
* ModuleTranslation.cpp: numArguments is unsigned and we know that .begin() is earlier than .end() so we can safely cast std::distance to size_t.
---
Full diff: https://github.com/llvm/llvm-project/pull/234999.diff
3 Files Affected:
- (modified) mlir/include/mlir/IR/OperationSupport.h (+2-2)
- (modified) mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp (+1-1)
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+2-1)
``````````diff
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 3b43a1cf07bf99..ec0bbf94096950 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -830,8 +830,8 @@ std::pair<IteratorT, bool> findAttrSorted(IteratorT first, IteratorT last,
template <typename IteratorT>
std::pair<IteratorT, bool> findAttrSorted(IteratorT first, IteratorT last,
StringAttr name) {
- constexpr unsigned kSmallAttributeList = 16;
- if (std::distance(first, last) > kSmallAttributeList)
+ constexpr size_t kSmallAttributeList = 16;
+ if (static_cast<size_t>(std::distance(first, last)) > kSmallAttributeList)
return findAttrSorted(first, last, name.strref());
return findAttrUnsorted(first, last, name);
}
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index 288eeb9cc1a8d8..6f58ecadc50ba4 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
@@ -2346,7 +2346,7 @@ struct ReinterpretCastOpConstantFolder
LogicalResult matchAndRewrite(ReinterpretCastOp op,
PatternRewriter &rewriter) const override {
- unsigned srcStaticCount = llvm::count_if(
+ auto srcStaticCount = llvm::count_if(
llvm::concat<OpFoldResult>(op.getMixedOffsets(), op.getMixedSizes(),
op.getMixedStrides()),
[](OpFoldResult ofr) { return isa<Attribute>(ofr); });
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index c0019a278b4a6d..b6efb2657bd994 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -906,7 +906,8 @@ void mlir::LLVM::detail::connectPHINodes(Region ®ion,
llvm::BasicBlock *llvmBB = state.lookupBlock(&bb);
auto phis = llvmBB->phis();
auto numArguments = bb.getNumArguments();
- assert(numArguments == std::distance(phis.begin(), phis.end()));
+ assert(numArguments ==
+ static_cast<size_t>(std::distance(phis.begin(), phis.end())));
for (auto [index, phiNode] : llvm::enumerate(phis)) {
for (auto *pred : bb.getPredecessors()) {
// Find the LLVM IR block that contains the converted terminator
``````````
</details>
https://github.com/llvm/llvm-project/pull/234999
More information about the Mlir-commits
mailing list