Skip to content

Commit 9a46060

Browse files
authored
[mlir][linalg] Fix crash caused by nullptr dereference (llvm#163132)
This PR fixes a crash caused by nullptr dereference in `isContractionBody` if reductionOp is nullptr. Fixes llvm#162772.
1 parent 96da982 commit 9a46060

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ bool mlir::linalg::detail::isContractionBody(
315315

316316
Value yielded = getSourceSkipUnary(terminator->getOperand(0));
317317
Operation *reductionOp = yielded.getDefiningOp();
318-
if (reductionOp->getNumResults() != 1 || reductionOp->getNumOperands() != 2) {
318+
if (!reductionOp || reductionOp->getNumResults() != 1 ||
319+
reductionOp->getNumOperands() != 2) {
319320
errs << "expected reduction op to be binary";
320321
return false;
321322
}

mlir/test/Dialect/Linalg/match-ops-interpreter.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,20 @@ module attributes { transform.target_tag = "start_here" } {
10111011
} -> tensor<1x1x4xf32>
10121012
return
10131013
}
1014+
1015+
func.func @generic_none(%arg0: tensor<128x128xi32>, %arg1: tensor<128x128xi32>, %arg2: tensor<128x128xi32>) {
1016+
%0 = linalg.generic {
1017+
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>,
1018+
affine_map<(d0, d1, d2) -> (d2, d1)>,
1019+
affine_map<(d0, d1, d2) -> (d0, d1)>],
1020+
iterator_types = ["parallel", "parallel", "reduction"]}
1021+
ins(%arg0, %arg1 : tensor<128x128xi32>, tensor<128x128xi32>)
1022+
outs(%arg2 : tensor<128x128xi32>) {
1023+
^bb0(%in: i32, %in_0: i32, %out: i32):
1024+
linalg.yield %out : i32
1025+
} -> tensor<128x128xi32>
1026+
return
1027+
}
10141028
}
10151029

10161030
// -----

0 commit comments

Comments
 (0)