Skip to content

Commit

Permalink
[MLIR][Affine] Add check for 'affine.for' Bound Map Results (llvm#127105
Browse files Browse the repository at this point in the history
)

Fixes issue llvm#120001.

Add missing check in affine.for op's verifier for lower/upper bound maps
to have at least one result.
  • Loading branch information
ayokunle321 authored Feb 22, 2025
1 parent 4448596 commit dc72a93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/Affine/IR/AffineOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions mlir/test/Dialect/Affine/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit dc72a93

Please sign in to comment.