summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h4
-rw-r--r--src/wasm-validator.h3
-rw-r--r--test/dot_s/unreachable_blocks.wast4
3 files changed, 11 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) {
diff --git a/test/dot_s/unreachable_blocks.wast b/test/dot_s/unreachable_blocks.wast
index a0a1daadc..f1593a00c 100644
--- a/test/dot_s/unreachable_blocks.wast
+++ b/test/dot_s/unreachable_blocks.wast
@@ -15,6 +15,7 @@
(i32.const 2)
)
(block $label$0 i32
+ (unreachable)
)
)
(func $unreachable_block_i64 (result i64)
@@ -22,6 +23,7 @@
(i64.const 3)
)
(block $label$0 i64
+ (unreachable)
)
)
(func $unreachable_block_f32 (result f32)
@@ -29,6 +31,7 @@
(f32.const 4.5)
)
(block $label$0 f32
+ (unreachable)
)
)
(func $unreachable_block_f64 (result f64)
@@ -36,6 +39,7 @@
(f64.const 5.5)
)
(block $label$0 f64
+ (unreachable)
)
)
(func $unreachable_loop_void