Skip to content
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

wasm-interp: Fix catch handlers' value stack sizes #2478

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

SoniEx2
Copy link
Contributor

@SoniEx2 SoniEx2 commented Oct 1, 2024

Fixes the value stack size of the catch handler. There were two (related) issues here:

  • The previous code used func_->locals.size() as soon as the function was available, but it hadn't processed the function's locals yet, so it was always empty. (This might not matter in practice, as it's only used by the "function-wide catch handler", which just rethrows.)
  • The previous code didn't take the function's locals into account when computing the value stack height (relative to the function frame) for a try-catch block. So, it would drop the locals when catching an exception.

Closes #2476

(Split from #2470 )

@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Oct 1, 2024

@sbc100

@sbc100 sbc100 changed the title interp: Fix catch handlers' value stack sizes wasm-interp: Fix catch handlers' value stack sizes Oct 1, 2024
Istream::kInvalidOffset,
{},
{Istream::kInvalidOffset},
static_cast<u32>(local_decl_count_),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous code uses func_->locals.size() here. How is that different? Perhaps you could mention in the PR description how the old code is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -856,6 +849,16 @@ Result BinaryReaderInterp::EndFunctionBody(Index index) {
Result BinaryReaderInterp::OnLocalDeclCount(Index count) {
local_decl_count_ = count;
local_count_ = 0;
// FIXME(Soni): does the value of `values` even matter here? it used to be
// always 0 when this call was in BeginFunctionBody.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this FIXME comment is useful, maybe just remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's fair.

... ugh, the more we look at all this code the more questionable stuff we find, like the func_->handlers.size() in BeginFunctionBody (which, presumably, always evaluates to 0?). but that's not the fix we came here for.

@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Oct 1, 2024

@sbc100 ping?

@sbc100 sbc100 merged commit 84ea5d3 into WebAssembly:main Oct 1, 2024
18 checks passed
@SoniEx2 SoniEx2 deleted the ehv3-interp-fix branch October 2, 2024 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

weird bug with exception handling (interpreter)
2 participants