Skip to content

Commit 4596b98

Browse files
authored
[Parser] Error properly on br_on* going to a target without a value (#7338)
Internally we subtract 1 from the number of values while processing such things, but if we start with 0 we'd overflow and hit a confusing error later. Fixes the last part of #7337
1 parent 7c6df82 commit 4596b98

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/wasm/wasm-ir-builder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,9 @@ Result<> IRBuilder::makeBrOn(Index label, BrOnOp op, Type in, Type out) {
19741974
case BrOnCast:
19751975
case BrOnCastFail:
19761976
// Modeled as sending one value.
1977+
if (extraArity == 0) {
1978+
return Err{"br_on target does not expect a value"};
1979+
}
19771980
extraArity -= 1;
19781981
break;
19791982
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
;; RUN: not wasm-opt %s -all 2>&1 | filecheck %s
2+
3+
;; Check we error properly when a block has no value, but a br_on with a value
4+
;; targets it.
5+
6+
(module
7+
;; CHECK: 10:7: error: br_on target does not expect a value
8+
(func $f
9+
(block $foo
10+
(br_on_cast $foo (ref eq) (ref eq)
11+
(ref.i31
12+
(i32.const 0)
13+
)
14+
)
15+
)
16+
)
17+
)

0 commit comments

Comments
 (0)