[Mlir-commits] [mlir] [mlir] Fix some different sign comparison warnings (PR #234999)

David Spickett llvmlistbot at llvm.org
Fri Oct 23 08:47:20 PDT 2026


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/234999

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, then 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.

>From e23858139a8d5c21cf011bf13dd279df2aeba6e9 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Fri, 23 Oct 2026 14:36:17 +0000
Subject: [PATCH] [mlir] Fix some different sign comparison warnings

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, then 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.
---
 mlir/include/mlir/IR/OperationSupport.h      | 4 ++--
 mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp     | 2 +-
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)

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 &region,
     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



More information about the Mlir-commits mailing list