Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/shared-validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ Result SharedValidator::BeginFunctionBody(const Location& loc,
Index func_index) {
expr_loc_ = loc;
locals_.clear();
local_ref_is_set_.clear();
local_refs_map_.clear();
if (func_index < funcs_.size()) {
for (Type type : funcs_[func_index].params) {
// TODO: Coalesce parameters of the same type?
Expand Down Expand Up @@ -1420,6 +1422,7 @@ Result SharedValidator::BeginTryTable(const Location& loc, Type sig_type) {
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
&result_types);
result |= typechecker_.BeginTryTable(param_types);
SaveLocalRefs();
return result;
}

Expand All @@ -1444,6 +1447,7 @@ Result SharedValidator::EndTryTable(const Location& loc, Type sig_type) {
TypeVector param_types, result_types;
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
&result_types);
RestoreLocalRefs(result);
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 realized I misunderstood how BeginTryTable/EndTryTable work. This is a new part of the code for me. BinaryReaderInterp::OnTryTableExpr calls EndTryTable after catch blocks are processed, not after the end.

In this case this is not needed (although harmless), and the normal OnEnd should call RestoreLocalRefs (it does).
I am sorry, I will submit another fix.

result |= typechecker_.EndTryTable(param_types, result_types);
return result;
}
Expand Down
24 changes: 24 additions & 0 deletions test/regress/regress-2670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;;; TOOL: run-roundtrip
;;; ARGS: --stdout --fold-exprs --generate-names --enable-function-references --enable-exceptions

;; This test was failed because the "local is set" bitvector
;; was not cleared in BeginFunctionBody, and the bitvector
;; save/restore operations was missing for try tables

(module
(func (local (ref func)))
(func
unreachable
try_table
end))

(;; STDOUT ;;;
(module
(type $t0 (func))
(func $f0 (type $t0)
(local $l0 (ref func)))
(func $f1 (type $t0)
(unreachable)
(try_table $T0
)))
;;; STDOUT ;;)
Loading