Skip to content

Commit 77655f4

Browse files
[mlir][arith] Assert preconditions in BitcastOp::fold. (#100743)
This PR adds an assertion to `BitcastOp::fold` that fails if that function is called on invalid IR. That can happen when patterns, passes, etc. create (invalid) IR using builders and folding is triggered on that IR before verification, for example, through `OpBuilder::createOrFold`. The new assert triggers earlier than previously in order to help getting to the root cause faster. Signed-off-by: Ingo Müller <[email protected]>
1 parent 13d39cb commit 77655f4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,8 @@ OpFoldResult arith::BitcastOp::fold(FoldAdaptor adaptor) {
17391739
APInt bits = llvm::isa<FloatAttr>(operand)
17401740
? llvm::cast<FloatAttr>(operand).getValue().bitcastToAPInt()
17411741
: llvm::cast<IntegerAttr>(operand).getValue();
1742+
assert(resType.getIntOrFloatBitWidth() == bits.getBitWidth() &&
1743+
"trying to fold on broken IR: operands have incompatible types");
17421744

17431745
if (auto resFloatType = llvm::dyn_cast<FloatType>(resType))
17441746
return FloatAttr::get(resType,

0 commit comments

Comments
 (0)