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 @@ -209,8 +209,10 @@ assert(hasStaticShape() && "cannot get element count of dynamic shaped type"); auto shape = getShape(); int64_t num = 1; - for (auto dim : shape) + for (auto dim : shape) { num *= dim; + assert(num >= 0 && "integer overflow in element count computation"); + } return num; } @@ -801,10 +803,12 @@ ? getAffineSymbolExpr(nSymbols++, context) : getAffineConstantExpr(runningSize, context); expr = expr ? expr + dimExpr * stride : dimExpr * stride; - if (size > 0) + if (size > 0) { runningSize *= size; - else + assert(runningSize > 0 && "integer overflow in size computation"); + } else { dynamicPoisonBit = true; + } } return simplifyAffineExpr(expr, numDims, nSymbols); }