diff options
Diffstat (limited to 'src/wasm-validator.h')
-rw-r--r-- | src/wasm-validator.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 988d1104d..3616313d3 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -61,10 +61,18 @@ public: if (curr->name.is()) { if (breakInfos.count(curr) > 0) { auto& info = breakInfos[curr]; + if (isConcreteWasmType(curr->type)) { + shouldBeTrue(info.arity != 0, curr, "break arities must be > 0 if block has a value"); + } else { + shouldBeTrue(info.arity == 0, curr, "break arities must be 0 if block has no value"); + } // none or unreachable means a poison value that we should ignore - if consumed, it will error if (isConcreteWasmType(info.type) && isConcreteWasmType(curr->type)) { shouldBeEqual(curr->type, info.type, curr, "block+breaks must have right type if breaks return a value"); } + if (isConcreteWasmType(curr->type) && info.arity && info.type != unreachable) { + shouldBeEqual(curr->type, info.type, curr, "block+breaks must have right type if breaks have arity"); + } shouldBeTrue(info.arity != Index(-1), curr, "break arities must match"); if (curr->list.size() > 0) { auto last = curr->list.back()->type; @@ -85,6 +93,9 @@ public: } } } + if (!isConcreteWasmType(curr->type) && curr->list.size() > 0) { + shouldBeFalse(isConcreteWasmType(curr->list.back()->type), curr, "block with no value cannot have a last element with a value"); + } } static void visitPreLoop(WasmValidator* self, Expression** currp) { @@ -100,6 +111,9 @@ public: shouldBeEqual(info.arity, Index(0), curr, "breaks to a loop cannot pass a value"); } } + if (curr->type == none) { + shouldBeFalse(isConcreteWasmType(curr->body->type), curr, "bad body for a loop that has no value"); + } } void visitIf(If *curr) { @@ -288,6 +302,15 @@ public: shouldBeUnequal(curr->ifFalse->type, none, curr, "select right must be valid"); } + void visitDrop(Drop* curr) { + // TODO: assert on this, when tests pass + if (getenv("BINARYEN_WARN_DROP")) { + if (!(isConcreteWasmType(curr->value->type) || curr->value->type == unreachable)) { + std::cerr << "warning: bad drop " << curr << " in " << (getFunction() ? getFunction()->name : Name("?")) << '\n'; + } + } + } + void visitReturn(Return* curr) { if (curr->value) { if (returnType == unreachable) { |