summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-05-02 13:47:31 -0700
committerGitHub <noreply@github.com>2017-05-02 13:47:31 -0700
commite10a6e22921889970ceb6e1fb76e786bc66d79d7 (patch)
tree78ac0b8dfd7ff9cc2758b8eb56197486d4ddb868 /src
parent5de55af88eaac818f86eaaec3f686eaede01397e (diff)
downloadbinaryen-e10a6e22921889970ceb6e1fb76e786bc66d79d7.tar.gz
binaryen-e10a6e22921889970ceb6e1fb76e786bc66d79d7.tar.bz2
binaryen-e10a6e22921889970ceb6e1fb76e786bc66d79d7.zip
disallow empty blocks with a type - if they return a type, they must have contents. make s2wasm avoid outputting that as well (#992)
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) {