Skip to content

Commit e9b4c9e

Browse files
authored
[Stack Switching] Validate continuation function subtyping (#7847)
1 parent 543990b commit e9b4c9e

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/wasm/wasm-validator.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,10 +3979,18 @@ void FunctionValidator::visitContNew(ContNew* curr) {
39793979
}
39803980
shouldBeTrue(curr->type.isExact(), curr, "cont.new should be exact");
39813981

3982-
shouldBeTrue(curr->type.isContinuation() &&
3983-
curr->type.getHeapType().getContinuation().type.isSignature(),
3982+
if (!shouldBeTrue(curr->type.isContinuation(),
3983+
curr,
3984+
"cont.new must be annotated with a continuation type")) {
3985+
return;
3986+
}
3987+
3988+
auto cont = curr->type.getHeapType().getContinuation();
3989+
assert(cont.type.isSignature());
3990+
3991+
shouldBeTrue(HeapType::isSubType(curr->func->type.getHeapType(), cont.type),
39843992
curr,
3985-
"cont.new must be annotated with a continuation type");
3993+
"cont.new function reference must be a subtype");
39863994
}
39873995

39883996
void FunctionValidator::visitContBind(ContBind* curr) {

test/spec/cont.wast

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@
242242
(type $c2 (cont $f2))
243243
)
244244

245+
(assert_invalid
246+
(module
247+
(rec
248+
(type $fA (func))
249+
(type $fB (func))
250+
(type $cont (cont $fA))
251+
)
252+
(elem declare func $b)
253+
(func $a
254+
(drop
255+
(cont.new $cont ;; expects a ref of $fA, not $fB
256+
(ref.func $b)
257+
)
258+
)
259+
)
260+
(func $b (type $fB)
261+
)
262+
)
263+
"type mismatch")
264+
245265
;; Simple state example
246266

247267
(module $state

0 commit comments

Comments
 (0)