diff --git a/mlir/include/mlir/IR/BuiltinTypes.h b/mlir/include/mlir/IR/BuiltinTypes.h --- a/mlir/include/mlir/IR/BuiltinTypes.h +++ b/mlir/include/mlir/IR/BuiltinTypes.h @@ -456,7 +456,9 @@ MLIRContext *context); /// Return the result of makeCanonicalStrudedLayoutExpr for the common case -/// where `exprs` is {d0, d1, .., d_(sizes.size()-1)} +/// where `exprs` is {d0, d1, .., d_(sizes.size()-1)}. Returns null if there +/// is an integer overflow during computation of the expression (i.e., 64-bits +/// aren't enough to store the strides). AffineExpr makeCanonicalStridedLayoutExpr(ArrayRef sizes, MLIRContext *context); diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -803,6 +803,8 @@ return success(); auto stridedExpr = makeCanonicalStridedLayoutExpr(t.getShape(), t.getContext()); + if (!stridedExpr) + return failure(); if (succeeded(extractStrides(stridedExpr, one, strides, offset))) return success(); assert(false && "unexpected failure: extract strides in canonical layout"); @@ -988,7 +990,11 @@ expr = expr ? expr + dimExpr * stride : dimExpr * stride; if (size > 0) { runningSize *= size; - assert(runningSize > 0 && "integer overflow in size computation"); + if (runningSize <= 0) { + emitError(UnknownLoc::get(context), + "integer overflow during size computation"); + return AffineExpr(); + } } else { dynamicPoisonBit = true; }