summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h4
-rw-r--r--src/wasm-validator.h3
2 files changed, 7 insertions, 0 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 9c50aeedd..d0579a402 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -1182,6 +1182,10 @@ class S2WasmBuilder {
} else if (match("end_block")) {
auto* block = bstack.back()->cast<Block>();
block->finalize(block->type);
+ if (isConcreteWasmType(block->type) && block->list.size() == 0) {
+ // empty blocks that return a value are not valid, fix that up
+ block->list.push_back(allocator->alloc<Unreachable>());
+ }
bstack.pop_back();
} else if (peek(".LBB")) {
// FIXME legacy tests: it can be leftover from "loop" or "block", but it can be a label too
diff --git a/src/wasm-validator.h b/src/wasm-validator.h
index 00a35fb24..29787a510 100644
--- a/src/wasm-validator.h
+++ b/src/wasm-validator.h
@@ -142,6 +142,9 @@ public:
}
}
}
+ if (isConcreteWasmType(curr->type)) {
+ shouldBeTrue(curr->list.size() > 0, curr, "block with a value must not be empty");
+ }
}
static void visitPreLoop(WasmValidator* self, Expression** currp) {