EffectAnalyzer: Do not reorder mayNotReturn with traps or global writes - #9211
Merged
Merged
Conversation
Expressions that may not return (loops, atomic.wait, struct.wait) can fail to terminate, which would prevent a subsequent trap or global state write (including calls) from ever executing. Update EffectAnalyzer::orderedBefore to disallow reordering mayNotReturn with traps or global writes, set mayNotReturn on AtomicWait, and clear loopEffects.mayNotReturn in LoopInvariantCodeMotion for the whole loop summary. Fixes #9182.
kripken
reviewed
Oct 5, 2026
| // Cannot reorder code that may not return with traps or global state | ||
| // changes. | ||
| if ((mayNotReturn && (other.trap || other.writesGlobalState())) || | ||
| (other.mayNotReturn && (trap || writesGlobalState()))) { |
Member
There was a problem hiding this comment.
Why handle traps and not throws etc?
Member
Author
There was a problem hiding this comment.
The throws case and other control flow cases are already handled here: https://github.com/WebAssembly/binaryen/pull/9211/changes#diff-963609105fd78eff33b9674f5f72d45b5b8dbb8d8e4c866085fdd8c994b51a84R341-R345. mayNotReturn is already considered a side effect, so it is not reordered with respect to control flow.
kripken
approved these changes
Oct 5, 2026
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.
Expressions that may not return (loops, atomic.wait, struct.wait) can fail to terminate, which would prevent a subsequent trap or global state write (including calls) from ever executing. Update EffectAnalyzer::orderedBefore to disallow reordering mayNotReturn with traps or global writes, set mayNotReturn on AtomicWait, and clear loopEffects.mayNotReturn in LoopInvariantCodeMotion for the whole loop summary.
Fixes #9182.