diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index cfc51ad2a1524..c4891614662a1 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -1902,6 +1902,10 @@ LogicalResult AffineForOp::verifyRegions() { if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(), getUpperBoundMap().getNumDims()))) return failure(); + if (getLowerBoundMap().getNumResults() < 1) + return emitOpError("expected lower bound map to have at least one result"); + if (getUpperBoundMap().getNumResults() < 1) + return emitOpError("expected upper bound map to have at least one result"); unsigned opNumResults = getNumResults(); if (opNumResults == 0) diff --git a/mlir/test/Dialect/Affine/invalid.mlir b/mlir/test/Dialect/Affine/invalid.mlir index da2913e3fec28..69d58ce1b5265 100644 --- a/mlir/test/Dialect/Affine/invalid.mlir +++ b/mlir/test/Dialect/Affine/invalid.mlir @@ -541,3 +541,25 @@ func.func @dynamic_dimension_index() { }) : () -> () return } + +// ----- + +#map = affine_map<() -> ()> +#map1 = affine_map<() -> (1)> +func.func @no_lower_bound() { + // expected-error@+1 {{'affine.for' op expected lower bound map to have at least one result}} + affine.for %i = max #map() to min #map1() { + } + return +} + +// ----- + +#map = affine_map<() -> ()> +#map1 = affine_map<() -> (1)> +func.func @no_upper_bound() { + // expected-error@+1 {{'affine.for' op expected upper bound map to have at least one result}} + affine.for %i = max #map1() to min #map() { + } + return +}