[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:55 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (fjsyrmia)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/83823.diff


1 Files Affected:

- (modified) mlir/lib/Dialect/Tosa/IR/TosaOps.cpp (+5-1) 


``````````diff
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(

``````````

</details>


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


More information about the Mlir-commits mailing list