diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index 4754f0bfe895e..77a56fb463243 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -584,6 +584,10 @@ void ForOp::print(OpAsmPrinter &p) { LogicalResult ForOp::verifyRegions() { // Check that the body defines as single block argument for the induction // variable. + if (getBody()->getNumArguments() == 0) + return emitOpError("expected body to have a single block argument for the " + "induction variable"); + if (getInductionVar().getType() != getLowerBound().getType()) return emitOpError( "expected induction variable to be same type as bounds and step"); diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir index 5f594fb08c43f..f30a614a93de0 100644 --- a/mlir/test/Dialect/EmitC/invalid_ops.mlir +++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir @@ -876,3 +876,28 @@ func.func @test_do(%arg0 : !emitc.ptr) { return } + +// ----- + +func.func @test_for_none_block_argument(%arg0: index) { + // expected-error@+1 {{expected body to have a single block argument for the induction variable}} + "emitc.for"(%arg0, %arg0, %arg0) ( + { + emitc.yield + } + ) : (index, index, index) -> () + return +} + +// ----- + +func.func @test_for_unmatch_type(%arg0: index) { + // expected-error@+1 {{expected induction variable to be same type as bounds}} + "emitc.for"(%arg0, %arg0, %arg0) ( + { + ^bb0(%i0 : f32): + emitc.yield + } + ) : (index, index, index) -> () + return +}