Fix: bail out when divisor is zero (#133518)

Fixes: #131279
This commit is contained in:
AdityaK 2025-04-02 09:44:18 -07:00 committed by GitHub
parent efca37fda5
commit 340f06a8d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -1124,7 +1124,7 @@ OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
if (!lhs)
return nullptr;
auto rhs = llvm::dyn_cast_if_present<IntegerAttr>(adaptor.getRhs());
if (!rhs)
if (!rhs || rhs.getValue().isZero())
return nullptr;
// Division in APInt does not follow floor(lhs, rhs) when the result is

View File

@ -0,0 +1,13 @@
// Bug: #131279
// RUN: mlir-opt --test-scf-pipelining %s | FileCheck %s
// CHECK: fold_div_index_neg_rhs
// CHECK-NEXT: %c0 = arith.constant 0 : index
// CHECK-NEXT: %0 = shape.div %c0, %c0 : index, index -> index
// CHECK-NEXT: return %0 : index
module {
func.func @fold_div_index_neg_rhs() -> index {
%c0 = arith.constant 0 : index
%0 = shape.div %c0, %c0 : index, index -> index
return %0 : index
}
}