Skip to content

Commit 68a30e1

Browse files
committed
Fix incorrect local is set management for try tables
1 parent 3071dba commit 68a30e1

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

src/shared-validator.cc

Lines changed: 1 addition & 1 deletion
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

@@ -1448,6 +1447,7 @@ Result SharedValidator::EndTryTable(const Location& loc, Type sig_type) {
14481447
result |= CheckBlockSignature(loc, Opcode::TryTable, sig_type, &param_types,
14491448
&result_types);
14501449
result |= typechecker_.EndTryTable(param_types, result_types);
1450+
SaveLocalRefs();
14511451
return result;
14521452
}
14531453

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: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +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)))
1012
(func
13+
(local (ref func) (ref func))
1114
try_table
1215
end)
16+
(func
17+
(local (ref func))
18+
try_table (catch $e0 0) (catch_all 0)
19+
end)
1320
(func
1421
unreachable
1522
try_table
@@ -19,12 +26,19 @@
1926
(module
2027
(type $t0 (func))
2128
(func $f0 (type $t0)
22-
(local $l0 (ref func)))
29+
(local $l0 (ref func)) (local $l1 (ref func)) (local $l2 (ref func)))
2330
(func $f1 (type $t0)
31+
(local $l0 (ref func)) (local $l1 (ref func))
2432
(try_table $T0
2533
))
2634
(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)
2740
(unreachable)
2841
(try_table $T0
29-
)))
42+
))
43+
(tag $e0 (type $t0)))
3044
;;; STDOUT ;;)

0 commit comments

Comments
 (0)