[Mlir-commits] [mlir] [mlir][Transforms] Check for correct type converter rule implementation (PR #140347)

Matthias Springer llvmlistbot at llvm.org
Fri May 16 21:22:10 PDT 2025


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/140347

If a type conversion rule fails to apply, it should not append any types to the result. This commit just adds an assertion to detect such cases of incorrect API usage.


>From cb78eb0d23627ad3563358b575646bf52d220e00 Mon Sep 17 00:00:00 2001
From: Matthias Springer <mspringer at nvidia.com>
Date: Sat, 17 May 2025 06:20:12 +0200
Subject: [PATCH] [mlir][Transforms] Check for correct type converter rule
 implementation

---
 mlir/lib/Transforms/Utils/DialectConversion.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 0d208ce0f2f25..bd11bbe58a3f6 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2880,6 +2880,8 @@ LogicalResult TypeConverter::convertType(Type t,
       if (t.getContext()->isMultithreadingEnabled())
         cacheWriteLock.lock();
       if (!succeeded(*result)) {
+        assert(results.size() == currentCount &&
+               "failed type conversion should not change results");
         cachedDirectConversions.try_emplace(t, nullptr);
         return failure();
       }
@@ -2889,6 +2891,9 @@ LogicalResult TypeConverter::convertType(Type t,
       else
         cachedMultiConversions.try_emplace(t, llvm::to_vector<2>(newTypes));
       return success();
+    } else {
+      assert(results.size() == currentCount &&
+             "failed type conversion should not change results");
     }
   }
   return failure();



More information about the Mlir-commits mailing list