Skip to content

Commit 0f5ba6f

Browse files
authored
Save local set data in EndTryTable (#2673)
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.
1 parent ade2a41 commit 0f5ba6f

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

src/shared-validator.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ Result SharedValidator::BeginTryTable(const Location& loc, Type sig_type) {
14221422
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
14231423
&result_types);
14241424
result |= typechecker_.BeginTryTable(param_types);
1425-
SaveLocalRefs();
14261425
return result;
14271426
}
14281427

@@ -1447,8 +1446,8 @@ Result SharedValidator::EndTryTable(const Location& loc, Type sig_type) {
14471446
TypeVector param_types, result_types;
14481447
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
14491448
&result_types);
1450-
RestoreLocalRefs(result);
14511449
result |= typechecker_.EndTryTable(param_types, result_types);
1450+
SaveLocalRefs();
14521451
return result;
14531452
}
14541453

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;;; TOOL: wat2wasm
2+
;;; ARGS: --enable-function-references --enable-exceptions
3+
;;; ERROR: 1
4+
(module
5+
(func (param (ref func))
6+
(local (ref func) (ref func))
7+
local.get 0
8+
local.set 1
9+
try_table
10+
try_table
11+
local.get 0
12+
local.set 2
13+
end
14+
local.get 1
15+
local.set 0
16+
local.get 2
17+
local.set 0
18+
end
19+
local.get 1
20+
local.set 0
21+
local.get 2
22+
local.set 0
23+
)
24+
)
25+
(;; STDERR ;;;
26+
out/test/parse/bad-refs-in-trytable.txt:16:17: error: uninitialized local reference
27+
local.get 2
28+
^
29+
out/test/parse/bad-refs-in-trytable.txt:21:15: error: uninitialized local reference
30+
local.get 2
31+
^
32+
;;; STDERR ;;)

test/regress/regress-2670.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
;; save/restore operations was missing for try tables
77

88
(module
9-
(func (local (ref func)))
9+
(tag $e0)
10+
11+
(func (local (ref func) (ref func) (ref func)))
12+
(func
13+
(local (ref func) (ref func))
14+
try_table
15+
end)
16+
(func
17+
(local (ref func))
18+
try_table (catch $e0 0) (catch_all 0)
19+
end)
1020
(func
1121
unreachable
1222
try_table
@@ -16,9 +26,19 @@
1626
(module
1727
(type $t0 (func))
1828
(func $f0 (type $t0)
19-
(local $l0 (ref func)))
29+
(local $l0 (ref func)) (local $l1 (ref func)) (local $l2 (ref func)))
2030
(func $f1 (type $t0)
31+
(local $l0 (ref func)) (local $l1 (ref func))
32+
(try_table $T0
33+
))
34+
(func $f2 (type $t0)
35+
(local $l0 (ref func))
36+
(try_table $T0
37+
(catch $e0 0 (;@0;))
38+
(catch_all 0 (;@0;))))
39+
(func $f3 (type $t0)
2140
(unreachable)
2241
(try_table $T0
23-
)))
42+
))
43+
(tag $e0 (type $t0)))
2444
;;; STDOUT ;;)

0 commit comments

Comments
 (0)