Skip to content

Commit ade2a41

Browse files
authored
Fix reference tracking in SharedValidator (#2672)
Clear "reference is set" bitset and hasmap in BeginFunctionBody. Furtermore support try_tables. Fixes: #2670
1 parent deb758e commit ade2a41

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/shared-validator.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ Result SharedValidator::BeginFunctionBody(const Location& loc,
540540
Index func_index) {
541541
expr_loc_ = loc;
542542
locals_.clear();
543+
local_ref_is_set_.clear();
544+
local_refs_map_.clear();
543545
if (func_index < funcs_.size()) {
544546
for (Type type : funcs_[func_index].params) {
545547
// TODO: Coalesce parameters of the same type?
@@ -1420,6 +1422,7 @@ Result SharedValidator::BeginTryTable(const Location& loc, Type sig_type) {
14201422
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
14211423
&result_types);
14221424
result |= typechecker_.BeginTryTable(param_types);
1425+
SaveLocalRefs();
14231426
return result;
14241427
}
14251428

@@ -1444,6 +1447,7 @@ Result SharedValidator::EndTryTable(const Location& loc, Type sig_type) {
14441447
TypeVector param_types, result_types;
14451448
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
14461449
&result_types);
1450+
RestoreLocalRefs(result);
14471451
result |= typechecker_.EndTryTable(param_types, result_types);
14481452
return result;
14491453
}

test/regress/regress-2670.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;;; TOOL: run-roundtrip
2+
;;; ARGS: --stdout --fold-exprs --generate-names --enable-function-references --enable-exceptions
3+
4+
;; This test was failed because the "local is set" bitvector
5+
;; was not cleared in BeginFunctionBody, and the bitvector
6+
;; save/restore operations was missing for try tables
7+
8+
(module
9+
(func (local (ref func)))
10+
(func
11+
unreachable
12+
try_table
13+
end))
14+
15+
(;; STDOUT ;;;
16+
(module
17+
(type $t0 (func))
18+
(func $f0 (type $t0)
19+
(local $l0 (ref func)))
20+
(func $f1 (type $t0)
21+
(unreachable)
22+
(try_table $T0
23+
)))
24+
;;; STDOUT ;;)

0 commit comments

Comments
 (0)