Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (getBody()->getNumArguments() == 0)
if (getBody()->getNumArguments() != 1)

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");
Expand Down
25 changes: 25 additions & 0 deletions mlir/test/Dialect/EmitC/invalid_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,28 @@ func.func @test_do(%arg0 : !emitc.ptr<i32>) {

return
}

// -----

func.func @test_for_none_block_argument(%arg0: index) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth adding a third case with more than one argument.

// 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
}