@@ -319,7 +319,13 @@ bool mlir::affine::isValidDim(Value value, Region *region) {
319
319
template <typename AnyMemRefDefOp>
320
320
static bool isMemRefSizeValidSymbol (AnyMemRefDefOp memrefDefOp, unsigned index,
321
321
Region *region) {
322
- auto memRefType = memrefDefOp.getType ();
322
+ MemRefType memRefType = memrefDefOp.getType ();
323
+
324
+ // Dimension index is out of bounds.
325
+ if (index >= memRefType.getRank ()) {
326
+ return false ;
327
+ }
328
+
323
329
// Statically shaped.
324
330
if (!memRefType.isDynamicDim (index))
325
331
return true ;
@@ -1651,19 +1657,22 @@ LogicalResult AffineDmaStartOp::verifyInvariantsImpl() {
1651
1657
if (!idx.getType ().isIndex ())
1652
1658
return emitOpError (" src index to dma_start must have 'index' type" );
1653
1659
if (!isValidAffineIndexOperand (idx, scope))
1654
- return emitOpError (" src index must be a dimension or symbol identifier" );
1660
+ return emitOpError (
1661
+ " src index must be a valid dimension or symbol identifier" );
1655
1662
}
1656
1663
for (auto idx : getDstIndices ()) {
1657
1664
if (!idx.getType ().isIndex ())
1658
1665
return emitOpError (" dst index to dma_start must have 'index' type" );
1659
1666
if (!isValidAffineIndexOperand (idx, scope))
1660
- return emitOpError (" dst index must be a dimension or symbol identifier" );
1667
+ return emitOpError (
1668
+ " dst index must be a valid dimension or symbol identifier" );
1661
1669
}
1662
1670
for (auto idx : getTagIndices ()) {
1663
1671
if (!idx.getType ().isIndex ())
1664
1672
return emitOpError (" tag index to dma_start must have 'index' type" );
1665
1673
if (!isValidAffineIndexOperand (idx, scope))
1666
- return emitOpError (" tag index must be a dimension or symbol identifier" );
1674
+ return emitOpError (
1675
+ " tag index must be a valid dimension or symbol identifier" );
1667
1676
}
1668
1677
return success ();
1669
1678
}
@@ -1752,7 +1761,8 @@ LogicalResult AffineDmaWaitOp::verifyInvariantsImpl() {
1752
1761
if (!idx.getType ().isIndex ())
1753
1762
return emitOpError (" index to dma_wait must have 'index' type" );
1754
1763
if (!isValidAffineIndexOperand (idx, scope))
1755
- return emitOpError (" index must be a dimension or symbol identifier" );
1764
+ return emitOpError (
1765
+ " index must be a valid dimension or symbol identifier" );
1756
1766
}
1757
1767
return success ();
1758
1768
}
@@ -2913,8 +2923,7 @@ static void composeSetAndOperands(IntegerSet &set,
2913
2923
}
2914
2924
2915
2925
// / Canonicalize an affine if op's conditional (integer set + operands).
2916
- LogicalResult AffineIfOp::fold (FoldAdaptor,
2917
- SmallVectorImpl<OpFoldResult> &) {
2926
+ LogicalResult AffineIfOp::fold (FoldAdaptor, SmallVectorImpl<OpFoldResult> &) {
2918
2927
auto set = getIntegerSet ();
2919
2928
SmallVector<Value, 4 > operands (getOperands ());
2920
2929
composeSetAndOperands (set, operands);
@@ -3005,18 +3014,19 @@ static LogicalResult
3005
3014
verifyMemoryOpIndexing (Operation *op, AffineMapAttr mapAttr,
3006
3015
Operation::operand_range mapOperands,
3007
3016
MemRefType memrefType, unsigned numIndexOperands) {
3008
- AffineMap map = mapAttr.getValue ();
3009
- if (map.getNumResults () != memrefType.getRank ())
3010
- return op->emitOpError (" affine map num results must equal memref rank" );
3011
- if (map.getNumInputs () != numIndexOperands)
3012
- return op->emitOpError (" expects as many subscripts as affine map inputs" );
3017
+ AffineMap map = mapAttr.getValue ();
3018
+ if (map.getNumResults () != memrefType.getRank ())
3019
+ return op->emitOpError (" affine map num results must equal memref rank" );
3020
+ if (map.getNumInputs () != numIndexOperands)
3021
+ return op->emitOpError (" expects as many subscripts as affine map inputs" );
3013
3022
3014
3023
Region *scope = getAffineScope (op);
3015
3024
for (auto idx : mapOperands) {
3016
3025
if (!idx.getType ().isIndex ())
3017
3026
return op->emitOpError (" index to load must have 'index' type" );
3018
3027
if (!isValidAffineIndexOperand (idx, scope))
3019
- return op->emitOpError (" index must be a dimension or symbol identifier" );
3028
+ return op->emitOpError (
3029
+ " index must be a valid dimension or symbol identifier" );
3020
3030
}
3021
3031
3022
3032
return success ();
@@ -3605,7 +3615,8 @@ LogicalResult AffinePrefetchOp::verify() {
3605
3615
Region *scope = getAffineScope (*this );
3606
3616
for (auto idx : getMapOperands ()) {
3607
3617
if (!isValidAffineIndexOperand (idx, scope))
3608
- return emitOpError (" index must be a dimension or symbol identifier" );
3618
+ return emitOpError (
3619
+ " index must be a valid dimension or symbol identifier" );
3609
3620
}
3610
3621
return success ();
3611
3622
}
0 commit comments