[Mlir-commits] [mlir] 71251e8 - [mlir] Fix -Wsign-compare in SparseTensorRewriting.cpp and Sparsification.cpp (NFC)

Jie Fu llvmlistbot at llvm.org
Tue Feb 14 19:58:24 PST 2023


Author: Jie Fu
Date: 2023-02-15T11:58:08+08:00
New Revision: 71251e8d4f3f26acb8692e5e1f23488d271f60e2

URL: https://github.com/llvm/llvm-project/commit/71251e8d4f3f26acb8692e5e1f23488d271f60e2
DIFF: https://github.com/llvm/llvm-project/commit/71251e8d4f3f26acb8692e5e1f23488d271f60e2.diff

LOG: [mlir] Fix -Wsign-compare in SparseTensorRewriting.cpp and Sparsification.cpp (NFC)

/home/jiefu/llvm-project/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp:279:33: error: comparison of integers of different signs: 'int64_t' (aka 'long') and 'const mlir::sparse_tensor::Level' (aka 'const unsigned long') [-Werror,-Wsign-compare]
    assert(env.op().getRank(&t) == lvlRank);
           ~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^~~~
1 error generated.

/home/jiefu/llvm-project/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp:788:29: error: comparison of integers of different signs: 'int64_t' (aka 'long') and 'const mlir::sparse_tensor::Dimension' (aka 'const unsigned long') [-Werror,-Wsign-compare]
    assert(srcRTT.getRank() == dimRank);
           ~~~~~~~~~~~~~~~~ ^  ~~~~~~~
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^~~~
/home/jiefu/llvm-project/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp:810:31: error: comparison of integers of different signs: 'int64_t' (aka 'long') and 'const mlir::sparse_tensor::Dimension' (aka 'const unsigned long') [-Werror,-Wsign-compare]
      assert(srcRTT.getRank() == dimRank);
             ~~~~~~~~~~~~~~~~ ^  ~~~~~~~
/usr/include/assert.h:93:27: note: expanded from macro 'assert'
     (static_cast <bool> (expr)                                         \
                          ^~~~
2 errors generated.

Added: 
    

Modified: 
    mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
    mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
index f6ef4cfffa4e..9ec1d7c22c80 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
@@ -785,7 +785,7 @@ struct ConvertRewriter : public OpRewritePattern<ConvertOp> {
     const Dimension dimRank = dstTp.getDimRank();
     // This assertion should be guaranteed by validity of the op,
     // but just for paranoia's sake.
-    assert(srcRTT.getRank() == dimRank);
+    assert(static_cast<Dimension>(srcRTT.getRank()) == dimRank);
 
     SmallVector<Value> srcSizes;
     sizesForTensor(rewriter, srcSizes, loc, srcRTT, src);
@@ -807,7 +807,7 @@ struct ConvertRewriter : public OpRewritePattern<ConvertOp> {
       srcRTT =
           getUnorderedCOOFromTypeWithOrdering(srcRTT, dstTp.getDimToLvlMap());
       // Ensure that mutating `srcRTT` didn't invalidate `dimRank`.
-      assert(srcRTT.getRank() == dimRank);
+      assert(static_cast<Dimension>(srcRTT.getRank()) == dimRank);
       tmpCoo = rewriter
                    .create<AllocTensorOp>(loc, srcRTT, dynSrcSizes, Value(),
                                           /*sizeHint=*/nnz, Attribute())

diff  --git a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
index 35558730ebd9..7f88c6a4d984 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp
@@ -276,7 +276,7 @@ static bool findSparseAnnotations(CodegenEnv &env) {
       annotated = true;
     const Level lvlRank = map.getNumResults();
     assert(!enc || lvlRank == enc.getLvlRank());
-    assert(env.op().getRank(&t) == lvlRank);
+    assert(static_cast<Level>(env.op().getRank(&t)) == lvlRank);
     for (Level l = 0; l < lvlRank; l++) {
       const unsigned tensor = t.getOperandNumber();
       // FIXME: `toOrigDim` is deprecated.


        


More information about the Mlir-commits mailing list