Skip to content

Commit dc72a93

Browse files
authored
[MLIR][Affine] Add check for 'affine.for' Bound Map Results (#127105)
Fixes issue #120001. Add missing check in affine.for op's verifier for lower/upper bound maps to have at least one result.
1 parent 4448596 commit dc72a93

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,10 @@ LogicalResult AffineForOp::verifyRegions() {
19021902
if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(),
19031903
getUpperBoundMap().getNumDims())))
19041904
return failure();
1905+
if (getLowerBoundMap().getNumResults() < 1)
1906+
return emitOpError("expected lower bound map to have at least one result");
1907+
if (getUpperBoundMap().getNumResults() < 1)
1908+
return emitOpError("expected upper bound map to have at least one result");
19051909

19061910
unsigned opNumResults = getNumResults();
19071911
if (opNumResults == 0)

mlir/test/Dialect/Affine/invalid.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,25 @@ func.func @dynamic_dimension_index() {
541541
}) : () -> ()
542542
return
543543
}
544+
545+
// -----
546+
547+
#map = affine_map<() -> ()>
548+
#map1 = affine_map<() -> (1)>
549+
func.func @no_lower_bound() {
550+
// expected-error@+1 {{'affine.for' op expected lower bound map to have at least one result}}
551+
affine.for %i = max #map() to min #map1() {
552+
}
553+
return
554+
}
555+
556+
// -----
557+
558+
#map = affine_map<() -> ()>
559+
#map1 = affine_map<() -> (1)>
560+
func.func @no_upper_bound() {
561+
// expected-error@+1 {{'affine.for' op expected upper bound map to have at least one result}}
562+
affine.for %i = max #map1() to min #map() {
563+
}
564+
return
565+
}

0 commit comments

Comments
 (0)