Skip to content

Commit 751e6c0

Browse files
[mlir][Transforms] Check for correct type converter rule implementation (#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.
1 parent 3040705 commit 751e6c0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,8 @@ LogicalResult TypeConverter::convertType(Type t,
28802880
if (t.getContext()->isMultithreadingEnabled())
28812881
cacheWriteLock.lock();
28822882
if (!succeeded(*result)) {
2883+
assert(results.size() == currentCount &&
2884+
"failed type conversion should not change results");
28832885
cachedDirectConversions.try_emplace(t, nullptr);
28842886
return failure();
28852887
}
@@ -2889,6 +2891,9 @@ LogicalResult TypeConverter::convertType(Type t,
28892891
else
28902892
cachedMultiConversions.try_emplace(t, llvm::to_vector<2>(newTypes));
28912893
return success();
2894+
} else {
2895+
assert(results.size() == currentCount &&
2896+
"failed type conversion should not change results");
28922897
}
28932898
}
28942899
return failure();

0 commit comments

Comments
 (0)