runtime: Fix printing failed allocation amounts. #17931
Open
+9
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
On LP64 and LLP64 systems, size_t is bigger than unsigned. Printing the failed allocation as mp_uint_t allows the correct failed allocation size to be shown. I noticed this in #17925.
However, there are occasions where mp_uint_t is bigger than size_t (nanbox). In that case, preserve the existing code path to avoid growth in executable size.
Example where this affects the failed allocation message (on x86_64 coverage build):
Before, this would print the size as 1. Now it prints it as 18014398509481985 (2**54 + 1).
solve, or what improvement does it add? Add links if relevant. -->
Testing
I built locally and verified that large failed allocations showed the correct value.
Trade-offs and Alternatives
The code ends up more complicated than it was previously, with the hope of avoiding code growth.
I can remove the added size assertions if preferred. I did want to see if the assertions were correct across all builds done by CI.