[Mlir-commits] [mlir] [mlir][affine] Fix crash in mlir::affine::getForInductionVarOwner() (PR #102625)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Aug 11 06:57:59 PDT 2024


https://github.com/DarshanRamakant updated https://github.com/llvm/llvm-project/pull/102625

>From ec0287127d67f1149d8e7617ac3f34ccce34fa7b Mon Sep 17 00:00:00 2001
From: Darshan Bhat <darshanbhatsirsi at gmail.com>
Date: Thu, 8 Aug 2024 16:30:41 +0530
Subject: [PATCH] [mlir][affine] Fix crash in
 lir::affine::getForInductionVarOwner()

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<BlockArgument>(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<AffineForOp>(containingInst))
+  if (auto forOp =
+          ivArg.getOwner()->getParent()->getParentOfType<AffineForOp>())
     // Check to make sure `val` is the induction variable, not an iter_arg.
     return forOp.getInductionVar() == val ? forOp : AffineForOp();
   return AffineForOp();



More information about the Mlir-commits mailing list