Skip to content

Conversation

@zherczeg
Copy link
Contributor

I have checked with gdb that OnEnd is really called. I hope I don't make more mistakes. I have also added the test case without unreachable, since the unreachable should not affect the bug, although it might trigger future bugs, so both should be present.

@zherczeg zherczeg changed the title EndTryTable does not need to local_ref_is_set_ EndTryTable does not need to restore local_ref_is_set_ Nov 23, 2025
@zherczeg zherczeg marked this pull request as draft November 23, 2025 04:25
@zherczeg
Copy link
Contributor Author

Ok try tables use a very different mechanism compared to normal blocks. I was able to trigger the issue in #2670 again with adding a local ref.

I checked the push / pop labels then.
Validator::BeginTryTableExpr -> SharedValidator::EndTryTable -> TypeChecker::EndTryTable -> TypeChecker::PushLabel
ExprVisitor::VisitExpr -> Validator::EndTryTableExpr -> SharedValidator::OnEnd -> TypeChecker::OnEnd -> TypeChecker::PopLabel

It looks like the BeginTryTable does not construct any labels. Probably because no code is generated then. The label construction happens at EndTryTable. Then the expressions are visited, and OnEnd is called by EndTryTableExpr. I don't know how the interpreter handles this, probably using its OnEndExpr.

I would need some help to understand how this code should work. Maybe more complex test cases are needed.

@zherczeg zherczeg marked this pull request as ready for review November 23, 2025 05:32
@zherczeg
Copy link
Contributor Author

If the code block of a try table is between EndTryTable .. EndTryTableExpr (=OnEnd), and the catch handlers has no side effects in SharedValidator, this patch is correct. Since I am not familiar with the try table implementation, there might be other rules.

@zherczeg zherczeg force-pushed the try_table_fix branch 3 times, most recently from 91593bf to 68a30e1 Compare November 23, 2025 08:36
@zherczeg zherczeg changed the title EndTryTable does not need to restore local_ref_is_set_ Save local set data in EndTryTable Nov 23, 2025
out/test/parse/bad-refs-in-trytable.txt:16:17: error: uninitialized local reference
local.get 2
^
out/test/parse/bad-refs-in-trytable.txt:21:15: error: uninitialized local reference
Copy link
Member

Choose a reason for hiding this comment

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

Is this is test that is missing from the upstream repo? Perhaps we should file an issue there, with the hope that can one day remove this downstream test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure I understand this question. I have created this test myself. The test checks that the "is set" bitset is correctly working. My code was wrong, I saved the bitset in a wrong place. I misunderstood the API sequence order for try_tables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you might refer to the failure. That is intentional, the WebAssembly set-before-use check is very simple.

The spec test interpreter also yields this error (although stops at the first error):
test.wast:13.17-13.18: validation error: uninitialized local

Copy link
Member

Choose a reason for hiding this comment

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

My question is basically this: If this is an interesting test case, why can't it be (or shouldn't it be) upstream in the spec repo. I guess this is question we should be asking of all of our local/downstream tests.

Copy link
Member

Choose a reason for hiding this comment

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

In any case this change LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If they are interested, why not. Anyway, it is possible that a similar test is already present in the spec test repo. The GC/function-references proposal don't have such test, since (reworked) exceptions is another proposal, but the full WebAssembly 3.0 test system may have.

@sbc100 sbc100 merged commit 0f5ba6f into WebAssembly:main Nov 24, 2025
17 checks passed
@zherczeg zherczeg deleted the try_table_fix branch November 25, 2025 03:30
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.

2 participants