Mehdi Amini 1cfc264547
[mlir][bufferization] Fix integer overflow crash in promote-buffers-to-stack (#186276)
`defaultIsSmallAlloc` called `ShapedType::getNumElements()` which
asserts when the static element count overflows `int64_t` (e.g. a
`memref<3090540x3090540x3090540xi32>` whose element count is ~29e18).

Switch to `ShapedType::tryGetNumElements()`, which returns
`std::nullopt` on overflow. An overflowing element count means the
allocation is definitely not small, so we return `false` immediately. A
secondary overflow guard is added for the final size comparison.

Fixes #64638

Assisted-by: Claude Code
2026-03-13 11:38:39 +00:00
..