summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-08-01 10:22:31 -0700
committerAlon Zakai <alonzakai@gmail.com>2017-08-01 10:22:31 -0700
commit114ed43b24d3c74112b922a7469c48c736172833 (patch)
tree13f28924c258d0eb29032164ddedc70a701dcdfd /src
parent04418d5617f6ab7015c5cf7b905b4775a5219f4b (diff)
downloadbinaryen-114ed43b24d3c74112b922a7469c48c736172833.tar.gz
binaryen-114ed43b24d3c74112b922a7469c48c736172833.tar.bz2
binaryen-114ed43b24d3c74112b922a7469c48c736172833.zip
fix proper wasm emitting of untaken br_tables
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-binary.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 88b967fdf..47bcc8ba5 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -666,6 +666,14 @@ void WasmBinaryWriter::visitSwitch(Switch *curr) {
recurse(curr->value);
}
recurse(curr->condition);
+ if (!BranchUtils::isBranchTaken(curr)) {
+ // if the branch is not taken, then it's dangerous to emit it, as
+ // wasm type checking rules are stricter than ours - we tolerate
+ // an untaken branch to a target with a different value, but not
+ // wasm. so just don't emit it
+ o << int8_t(BinaryConsts::Unreachable);
+ return;
+ }
o << int8_t(BinaryConsts::TableSwitch) << U32LEB(curr->targets.size());
for (auto target : curr->targets) {
o << U32LEB(getBreakIndex(target));
@@ -1796,7 +1804,7 @@ void WasmBinaryBuilder::processExpressions() { // until an end or else marker, o
Expression* WasmBinaryBuilder::popExpression() {
if (expressionStack.empty()) {
- throw ParseException("attempted pop from empty stack");
+ throw ParseException("attempted pop from empty stack at " + std::to_string(pos));
}
auto ret = expressionStack.back();
// to simulate the wasm polymorphic stack mode, leave a final