Skip to content

Commit ec1495d

Browse files
committed
[mlir][tosa] Fix crash in inferReturnTypes for ReduceOps
The `tosa.reduce_*` ops take an `axis` Attribute that determines along which dimension the reduction takes place. A crash can occur during shape inference when the input tensor rank is so low that the given axis doesn't exist. Fix #68187
1 parent c2f02e3 commit ec1495d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,8 @@ static LogicalResult ReduceInferReturnTypes(
11171117
SmallVector<int64_t> outputShape;
11181118
operandShape.getDims(outputShape);
11191119
int64_t axisVal = axis.getValue().getSExtValue();
1120-
outputShape[axisVal] = 1;
1120+
if (axisVal < operandShape.getRank())
1121+
outputShape[axisVal] = 1;
11211122
inferredReturnShapes.push_back(ShapedTypeComponents(outputShape, inputType));
11221123
return success();
11231124
}

0 commit comments

Comments
 (0)