Skip to content

Commit e629264

Browse files
authored
Properly error on a return in a non-function scope (WebAssembly#7256)
Without this we get an assertion later on, child-typer.h:720: Assertion `func' failed. Returns use the function to find the return values, so like local get and set, we must error early on lacking a function.
1 parent d26ad82 commit e629264

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/wasm/wasm-ir-builder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,9 @@ Result<> IRBuilder::makeDrop() {
16981698
}
16991699

17001700
Result<> IRBuilder::makeReturn() {
1701+
if (!func) {
1702+
return Err{"return is only valid in a function context"};
1703+
}
17011704
Return curr;
17021705
CHECK_ERR(visitReturn(&curr));
17031706
push(builder.makeReturn(curr.value));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
;; We should error properly on a return in a non-function scope
2+
3+
;; RUN: not wasm-opt %s 2>&1 | filecheck %s
4+
;; CHECK: Fatal: 8:5: error: return is only valid in a function context
5+
6+
(module
7+
(elem
8+
(return)
9+
)
10+
)

0 commit comments

Comments
 (0)