Skip to content

Commit d1bc41f

Browse files
[mlir][affine] Fix crash in mlir::affine::getForInductionVarOwner() (#102625)
This change fixes a crash when getOwner()->getParent() is a nullptr
1 parent 167c71a commit d1bc41f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,10 +2562,10 @@ bool mlir::affine::isAffineInductionVar(Value val) {
25622562

25632563
AffineForOp mlir::affine::getForInductionVarOwner(Value val) {
25642564
auto ivArg = llvm::dyn_cast<BlockArgument>(val);
2565-
if (!ivArg || !ivArg.getOwner())
2565+
if (!ivArg || !ivArg.getOwner() || !ivArg.getOwner()->getParent())
25662566
return AffineForOp();
2567-
auto *containingInst = ivArg.getOwner()->getParent()->getParentOp();
2568-
if (auto forOp = dyn_cast<AffineForOp>(containingInst))
2567+
if (auto forOp =
2568+
ivArg.getOwner()->getParent()->getParentOfType<AffineForOp>())
25692569
// Check to make sure `val` is the induction variable, not an iter_arg.
25702570
return forOp.getInductionVar() == val ? forOp : AffineForOp();
25712571
return AffineForOp();

0 commit comments

Comments
 (0)