[Mlir-commits] [mlir] [mlir][tosa] Prevent div by 0 in ReshapeOp::inferReturnTypeComponents (PR #83823)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Mar 4 03:10:12 PST 2024


https://github.com/fjsyrmia created https://github.com/llvm/llvm-project/pull/83823

Check if staticMul is 0 before division and return failure()
instead of undefined behavior.

>From 1b703d758bcabf66b447cdaab7ab2dc43046563c Mon Sep 17 00:00:00 2001
From: Filip Jankovic <Filip.Jankovic at syrmia.com>
Date: Mon, 4 Mar 2024 11:56:06 +0100
Subject: [PATCH] [mlir][tosa] Prevent div by 0 in
 ReshapeOp::inferReturnTypeComponents

---
 mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 62d07859e32f6e..bcde87ff158b47 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -936,8 +936,12 @@ LogicalResult tosa::ReshapeOp::inferReturnTypeComponents(
 
   // Determine the length of the dynamic dimension.
   for (auto &val : newShapeValue) {
-    if (ShapedType::isDynamic(val))
+    if (ShapedType::isDynamic(val)) {
+      if (staticMul == 0) {
+        return failure();
+      }
       val = numElements / staticMul;
+    }
   }
 
   inferredReturnShapes.push_back(



More information about the Mlir-commits mailing list