fix: prevent OutputStackOverflow in intrinsic i32::overflowing_sub#1165
Merged
Conversation
bitwalker
reviewed
Jun 10, 2026
bitwalker
left a comment
Collaborator
There was a problem hiding this comment.
This should not have been merged - this behavior in the processor with regard to the operand stack is known and expected, and is why we emit calls to core::sys::truncate_stack at the end of every program entrypoint - which is what should have been done here.
Let's revert this and adjust the test code instead to call that procedure like we do during codegen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1163
On top of #1160 to make use of intrinsic testing.
Problem
compiler/codegen/masm/intrinsics/i32.masm
Line 92 in 30544eb
The
dropwould cause stack depth to shrink below the minimum of 16, so the processor implicitly adds a stack slot by adjusting the bottom of the stack [ref].So after
drop push.MAXthe stack depth is 17 while in the intrinsic it's assumed to be 16. The extra slot isn't cleaned up, which results inOutputStackOverflow.Footgun?
MASM authors should probably be aware of this, still it can be a footgun. Could this be: