From d1bc41fdd1f531de2a0fdd02de03d43a11de6767 Mon Sep 17 00:00:00 2001 From: DarshanRamakant Date: Sun, 11 Aug 2024 23:51:37 +0530 Subject: [PATCH] [mlir][affine] Fix crash in mlir::affine::getForInductionVarOwner() (#102625) This change fixes a crash when getOwner()->getParent() is a nullptr --- mlir/lib/Dialect/Affine/IR/AffineOps.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp index 35d5f53aad241f..11b6b7cf5fd5a7 100644 --- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp +++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp @@ -2562,10 +2562,10 @@ bool mlir::affine::isAffineInductionVar(Value val) { AffineForOp mlir::affine::getForInductionVarOwner(Value val) { auto ivArg = llvm::dyn_cast(val); - if (!ivArg || !ivArg.getOwner()) + if (!ivArg || !ivArg.getOwner() || !ivArg.getOwner()->getParent()) return AffineForOp(); - auto *containingInst = ivArg.getOwner()->getParent()->getParentOp(); - if (auto forOp = dyn_cast(containingInst)) + if (auto forOp = + ivArg.getOwner()->getParent()->getParentOfType()) // Check to make sure `val` is the induction variable, not an iter_arg. return forOp.getInductionVar() == val ? forOp : AffineForOp(); return AffineForOp();