-
Notifications
You must be signed in to change notification settings - Fork 745
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
[EH] Add validation for new instructions #6185
Conversation
This adds validation for the new EH instructions (`try_table` and `throw_ref`): https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md This also adds a spec test for checking invalid modules. We cannot check the executions yet because we don't have the interpreter implementation. The new test file also contains tests for the existing `throw`, because this is meant to replace the old spec test someday.
if (curr->type != Type::unreachable) { | ||
shouldBeSubType(curr->body->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.
This can be combined with the else
case into a single shouldBeSubType
, since the only subtype of Type::unreachable
is Type::unreachable
.
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.
Done
src/wasm/wasm-validator.cpp
Outdated
if (shouldBeTrue(sentType.size() == 1, curr, "")) { | ||
shouldBeEqual(sentType, | ||
Type(Type::none), |
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 happening here? sentType
cannot both have size 1 and be equal to Type::none
, since Type::none
has size 0.
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.
So in case the sent type is none
, the sentTypes
will look like {Type(Type::none)}
, which is of size 1, no?
To make it contain the sent types that can be used directly at branch-utils.h
, in case there is no sent values, we add a single Type::none
:
Line 927 in eb5666e
curr->sentTypes.push_back(sentType.empty() ? Type::none : Type(sentType)); |
Usage in
branch-utils.h
binaryen/src/ir/branch-utils.h
Lines 78 to 84 in eb5666e
} else if (auto* tt = expr->dynCast<TryTable>()) { | |
for (Index i = 0; i < tt->catchTags.size(); i++) { | |
auto dest = tt->catchDests[i]; | |
if (dest == name) { | |
func(name, tt->sentTypes[i]); | |
} | |
} |
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.
We can make it {}
and branch-utils.h
's operateOnScopeNameUsesAndSentTypes
to return Type::none
in case there is an empty type, but that adds one more if
and operateOnScopeNameUsesAndSentTypes
runs more times than the routine popuating sentTypes
when reading a binary.
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.
Sorry, nevermind all above. I didn't know (Type::none).size()
returns 0. Will fix.
shouldBeEqual( | ||
tagType[j], sentType[j], curr, "invalid catch sent type information"); | ||
} | ||
if (curr->catchRefs[i]) { |
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.
It would be good to check that the sizes match when this is false as well. Alternatively, when there is no extra exnref, you can just check tagType == sentType
.
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.
This was actually incorrect because even if there is no values to send, sentType
will contain Type::none
, which is size 1... And this wasn't crashing because I was doing the early exit (https://github.com/WebAssembly/binaryen/pull/6185/files#diff-2149be365b66a82038f1d3fa8f9fb1b4dcd40ab535c986f4bf0a4c37e669a1ceR2481-R2483). Will fix that and check both cases.
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.
Nevermind the comment. Didn't know (Type::none).size()
returns 0...
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.
Ended up rewriting much of the loop, but I think I an now checking both cases. PTAL
Co-authored-by: Alon Zakai <[email protected]>
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.
Nice, LGTM!
src/wasm/wasm-validator.cpp
Outdated
Name tagName = curr->catchTags[i]; | ||
if (!tagName) { // catch_all or catch_all_ref | ||
tagTypeSize = 0; | ||
|
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.
nit: I think this extra newline looks a little odd.
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.
Removed it
This adds validation for the new EH instructions (`try_table` and `throw_ref`): https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md This also adds a spec test for checking invalid modules. We cannot check the executions yet because we don't have the interpreter implementation. The new test file also contains tests for the existing `throw`, because this is meant to replace the old spec test someday.
This adds validation for the new EH instructions (
try_table
andthrow_ref
):https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
This also adds a spec test for checking invalid modules. We cannot check the executions yet because we don't have the interpreter implementation. The new test file also contains tests for the existing
throw
, because this is meant to replace the old spec test someday.