Fix Stack::compare ignoring element results for different-sized stacks #8297
+22
−3
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
When comparing stacks of different sizes,
Stack::compareiterated from the top matching elements pairwise, accumulating a comparison result. However, when one stack was exhausted, it returnedLESSorGREATERbased solely on which stack was taller, ignoring any contradicting result from the element-wise comparisons.For example, with
Stack<Bool>comparing[true, false]against[true]:falsevstrue→LESSbis exhausted,ahas extra non-bottom elements → code returnedGREATERNO_RELATION(the element ordering conflicts with the size ordering)The fix checks the accumulated
resultbefore returning at the size-difference branches, returningNO_RELATIONwhen there is a conflict.Note: This bug was not caught by the lattice fuzzer because
Stackis not included in the fuzz variants inwasm-fuzz-lattices.cpp.Test plan
StackLattice.CompareDifferentSizeConflicttest case