Skip to content

Commit 8d9f5ac

Browse files
authored
Fix checking of delegate target block kind. (#1605)
As clarified in: WebAssembly/exception-handling#146 the delegate target cannot be a `block` or `loop`. This commit also adds a failure test that covers several cases discussed in that issue.
1 parent 6d6c37b commit 8d9f5ac

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/type-checker.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ Result TypeChecker::OnDelegate(Index depth) {
548548
// Delegate starts counting after the current try, as the delegate
549549
// instruction is not actually in the try block.
550550
CHECK_RESULT(GetLabel(depth + 1, &label));
551+
if (Failed(Check2LabelTypes(label, LabelType::Try, LabelType::Func))) {
552+
PrintError("try-delegate must target a try block or function label");
553+
result = Result::Error;
554+
}
551555

552556
Label* try_label;
553557
CHECK_RESULT(TopLabel(&try_label));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;;; TOOL: wat2wasm
2+
;;; ERROR: 1
3+
;;; ARGS: --enable-exceptions
4+
(module
5+
(event $e)
6+
(func
7+
try
8+
block
9+
try
10+
throw $e
11+
delegate 0
12+
end
13+
catch $e
14+
loop
15+
try
16+
throw $e
17+
delegate 0
18+
end
19+
try
20+
catch $e
21+
try
22+
delegate 0
23+
catch_all
24+
end
25+
end))
26+
(;; STDERR ;;;
27+
out/test/typecheck/bad-delegate-target.txt:9:9: error: try-delegate must target a try block or function label
28+
try
29+
^^^
30+
out/test/typecheck/bad-delegate-target.txt:15:7: error: try-delegate must target a try block or function label
31+
try
32+
^^^
33+
out/test/typecheck/bad-delegate-target.txt:21:7: error: try-delegate must target a try block or function label
34+
try
35+
^^^
36+
;;; STDERR ;;)

test/typecheck/delegate.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
(event $e)
55
(func
66
try
7-
block
7+
try
88
try
99
throw $e
1010
delegate 0
11+
catch $e
1112
end
1213
catch $e
1314
end)

0 commit comments

Comments
 (0)