summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp5
-rw-r--r--test/unit.wast12
-rw-r--r--test/unit.wast.from-wast12
-rw-r--r--test/unit.wast.fromBinary15
-rw-r--r--test/unit.wast.fromBinary.noDebugInfo15
5 files changed, 59 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 018e463e0..63dddbdd6 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -583,6 +583,11 @@ void WasmBinaryWriter::recursePossibleBlockContents(Expression* curr) {
for (auto* child : block->list) {
recurse(child);
}
+ if (block->type == unreachable && block->list.back()->type != unreachable) {
+ // similar to in visitBlock, here we could skip emitting the block itself,
+ // but must still end the 'block' (the contents, really) with an unreachable
+ o << int8_t(BinaryConsts::Unreachable);
+ }
}
void WasmBinaryWriter::visitIf(If *curr) {
diff --git a/test/unit.wast b/test/unit.wast
index c1a945264..a429675de 100644
--- a/test/unit.wast
+++ b/test/unit.wast
@@ -537,4 +537,16 @@
(if (i32.const 1) (nop) (unreachable))
(if (i32.const 1) (unreachable) (unreachable))
)
+ (func $unreachable-if-arm
+ (if
+ (i32.const 1)
+ (block
+ (nop)
+ )
+ (block
+ (unreachable)
+ (i32.const 1) ;; ends in a concrete, after an unreachable
+ )
+ )
+ )
)
diff --git a/test/unit.wast.from-wast b/test/unit.wast.from-wast
index bb66845af..7fb82d69d 100644
--- a/test/unit.wast.from-wast
+++ b/test/unit.wast.from-wast
@@ -602,4 +602,16 @@
(unreachable)
)
)
+ (func $unreachable-if-arm (type $FUNCSIG$v)
+ (if
+ (i32.const 1)
+ (block $block
+ (nop)
+ )
+ (block $block12
+ (unreachable)
+ (i32.const 1)
+ )
+ )
+ )
)
diff --git a/test/unit.wast.fromBinary b/test/unit.wast.fromBinary
index 78ae640b1..8bb80bcca 100644
--- a/test/unit.wast.fromBinary
+++ b/test/unit.wast.fromBinary
@@ -646,5 +646,20 @@
)
(unreachable)
)
+ (func $unreachable-if-arm (type $1)
+ (if
+ (i32.const 1)
+ (block $label$0
+ (nop)
+ )
+ (block $label$1
+ (unreachable)
+ (drop
+ (i32.const 1)
+ )
+ (unreachable)
+ )
+ )
+ )
)
diff --git a/test/unit.wast.fromBinary.noDebugInfo b/test/unit.wast.fromBinary.noDebugInfo
index 3c24886f5..09da9a15b 100644
--- a/test/unit.wast.fromBinary.noDebugInfo
+++ b/test/unit.wast.fromBinary.noDebugInfo
@@ -646,5 +646,20 @@
)
(unreachable)
)
+ (func $36 (type $1)
+ (if
+ (i32.const 1)
+ (block $label$0
+ (nop)
+ )
+ (block $label$1
+ (unreachable)
+ (drop
+ (i32.const 1)
+ )
+ (unreachable)
+ )
+ )
+ )
)