Repository navigation
Fix empty layout span sizes with overflowing extent prefixes - #489
vera-rubin wants to merge 1 commit into
Conversation
Check for zero factors before multiplying extents in padded mapping preconditions and required_span_size(). Cover every zero position in constexpr and runtime checks for both left and right layouts. Assisted-By: Codex / gpt-6.1-sol Signed-off-by: Nathan Chandrasekar <322284620+vera-rubin@users.noreply.github.com>
|
Thank you for your interest in mdspan and for wording to improve the quality of the reference implementation! I think this is a reasonable reading of the Standard. Here is my analysis. The padded layouts have specific wording to make The constructor's precondition says that the "size of the multidimensional index space" is representable as a value of type |
|
Hey Mark, I actually spent a bit of time reading through the standard yesterday night too, and agree with your interpretation. I scrolled through the changes, and I wondered in some places if we can do some perf optimizations. |
|
Another question: was this problem encountered in a real end-product or was this generated based on some green-field AI agent search of open source software? (I looked at the company website of the authors account). Just trying to understand the urgency of resolving the thing. I do believe it's a valid issue. |
|
To further evidence of my statement, the above code does compile without the changes in this PR, when using |
|
Thanks for checking the standard too. This came from our AI-assisted checks of libraries against the C++ standard, not from a failure in a shipped product, so there's no urgency on our side. Agreed on unsigned index types: wraparound already gives zero there, which matches what you saw compiling with |
With 32-bit
intindices, extents(65536, 65536, 0)abort during padded mapping construction with default precondition checks. Both unpadded layouts also rejectrequired_span_size()in constant evaluation because an intermediate product overflows, although the constructor precondition concerns the complete size, which is zero, and the required span is zero.We check for zero factors before multiplying in the padded representability checks and all four span observers. The regression covers both orientations and every zero position at compile time and runtime. We tested the full suite with GCC 13.3 in C++23 and the affected layout tests and reproducers in C++17, C++20 and C++23.
— ChipLab