-
Notifications
You must be signed in to change notification settings - Fork 821
Fix validation of typed select with empty result types (#2708) #2810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ba20b0e
435c6ad
73d0f3b
e6d3387
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ;;; TOOL: run-gen-wasm-bad | ||
| ;;; ERROR: 1 | ||
| ;;; RUN: %(wasm-interp)s --enable-all %(temp_file)s.wasm --run-export=run | ||
| ;;; ERROR3: 1 | ||
| magic | ||
| version | ||
| section(TYPE) { count[1] function params[0] results[1] i32 } | ||
| section(FUNCTION) { count[1] type[0] } | ||
| section(EXPORT) { count[1] str("run") func_kind 0 } | ||
| section(CODE) { | ||
| count[1] | ||
| func { | ||
| locals[0] | ||
| i32.const 42 | ||
| i32.const 100 | ||
| i32.const 1 | ||
| 0x1c | ||
| 0x00 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these two magic numbers? I think you can document by using the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sbc100 thanks for the feedback I have replaced the raw bytes with select_t[0x1c] and result_count[0x00] to make the test clearer. |
||
| end | ||
| } | ||
| } | ||
| (;; STDERR ;;; | ||
| 0000029: error: invalid arity in select instruction: 0. | ||
| 0000029: error: invalid arity in select instruction: 0. | ||
| 0000029: error: invalid arity in select instruction: 0. | ||
| ;;; STDERR ;;) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ;;; TOOL: wat2wasm | ||
| ;;; ERROR: 1 | ||
| (module | ||
| (func | ||
| i32.const 42 | ||
| i32.const 100 | ||
| i32.const 1 | ||
| select (result))) | ||
| (;; STDERR ;;; | ||
| out/test/parse/expr/bad-select-empty-result.txt:8:5: error: invalid arity in select instruction: 0. | ||
| select (result))) | ||
| ^^^^^^ | ||
| out/test/parse/expr/bad-select-empty-result.txt:8:5: error: type mismatch at end of function, expected [] but got [i32, i32, i32] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if the results are not consumed, the condition i32 should be.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zherczeg I have Fixed it . We now report the arity error but still run OnSelect, so the condition and operands are consumed correctly. I also updated the test with drop. |
||
| select (result))) | ||
| ^^^^^^ | ||
| ;;; STDERR ;;) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the zero-length result_type of imply that the expr has not result type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbc100 empty result_type can mean either “untyped select” or “invalid typed select with no types” — has_result_type distinguishes those, so I don’t think we can drop it without losing that check. (Not part of this PR though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do does
has_result_type = falsecorrespond to "untyped select".Maybe a comment here explaining the distinction and why this member is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of "untyped select"? This likely rare case could be represented by the void type.
Btw if "supporting untyped select" is not part of the PR, we should not introduce this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbc100 & @zherczeg Thanks for the feedback .
I removed has_result_type and now use {Type::Void} to represent the existing untyped select. An empty result_type now represents invalid typed select (result), and I added a comment documenting the distinction.