Fix typed select to propagate result type instead of Any#2698
Closed
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Closed
Fix typed select to propagate result type instead of Any#2698sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
In OnSelect(), when a typed select instruction has an explicit type annotation (non-empty expected vector), the code validates both operand types against expected[0] but never assigns the result_type. It remains Type::Any from initialization, so PushType(Type::Any) is called instead of pushing the declared result type. This violates the WebAssembly spec which requires a typed select to produce a value of the annotated type. The untyped select path already correctly sets result_type = type1; this commit applies the analogous fix for the typed path by setting result_type = expected[0].
Contributor
Author
|
Closing as duplicate of #2707. |
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.
Summary
When processing a typed
selectinstruction (one with an explicit type annotation),TypeChecker::OnSelect()validates both operand types against the expected type but never assigns the validated type toresult_type. It stays asType::Anyfrom initialization, causingPushType(Type::Any)instead of pushing the declared result type.This violates the WebAssembly spec, which requires a typed select to produce a value of the annotated type on the value stack. The untyped select path already correctly sets
result_type = type1; this fix applies the analogous assignment for the typed path:result_type = expected[0].The Fix
A single line addition after the type checks in the typed select branch:
result_type = expected[0];This ensures the annotated type flows through to
PushType(result_type)andPrintStackIfFailed().Test plan