Skip to content

Commit 0ef990d

Browse files
[mlir][bufferization] Improve verifier for bufferization.dealloc (llvm#67912)
Check that the number of retained operands and updated conditions match.
1 parent c77b2ad commit 0ef990d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ LogicalResult DeallocOp::verify() {
764764
if (getMemrefs().size() != getConditions().size())
765765
return emitOpError(
766766
"must have the same number of conditions as memrefs to deallocate");
767+
if (getRetained().size() != getUpdatedConditions().size())
768+
return emitOpError("must have the same number of updated conditions "
769+
"(results) as retained operands");
767770
return success();
768771
}
769772

mlir/test/Dialect/Bufferization/invalid.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ func.func @invalid_dealloc_wrong_number_of_results(%arg0: memref<2xf32>, %arg1:
8787
%0:2 = bufferization.dealloc (%arg0, %arg1 : memref<2xf32>, memref<4xi32>) if (%arg2, %arg2) retain (%arg1 : memref<4xi32>)
8888
return %0#0 : i1
8989
}
90+
91+
// -----
92+
93+
func.func @invalid_dealloc_wrong_number_of_results(%arg0: memref<2xf32>, %arg1: memref<4xi32>, %arg2: i1) -> i1 {
94+
// expected-error @below{{must have the same number of updated conditions (results) as retained operands}}
95+
%0:3 = "bufferization.dealloc"(%arg0, %arg1, %arg2, %arg2, %arg1) <{operandSegmentSizes = array<i32: 2, 2, 1>}> : (memref<2xf32>, memref<4xi32>, i1, i1, memref<4xi32>) -> (i1, i1, i1)
96+
return %0#0 : i1
97+
}

0 commit comments

Comments
 (0)