diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 15:59:58 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 18:42:48 -0700 |
commit | 282369b5430287c2397eb9e3cdd859ad12fa3937 (patch) | |
tree | df5f2b3d37c64cb8fd085f65c199b4244b650eed /src | |
parent | b518e564be25cc2705ab3993b71f0170feabac7e (diff) | |
download | binaryen-282369b5430287c2397eb9e3cdd859ad12fa3937.tar.gz binaryen-282369b5430287c2397eb9e3cdd859ad12fa3937.tar.bz2 binaryen-282369b5430287c2397eb9e3cdd859ad12fa3937.zip |
autodrop if body if no else
Diffstat (limited to 'src')
-rw-r--r-- | src/ast_utils.h | 7 | ||||
-rw-r--r-- | src/wasm-validator.h | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index f7a486332..5deaa6a2c 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -832,6 +832,13 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop, Visitor<Auto curr->finalize(); // we may have changed our type } + void visitIf(If* curr) { + // if without else does not return a value, so the body must be dropped if it is concrete + if (!curr->ifFalse && isConcreteWasmType(curr->ifTrue->type)) { + curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + } + } + void visitFunction(Function* curr) { if (curr->result == none && isConcreteWasmType(curr->body->type)) { curr->body = Builder(*getModule()).makeDrop(curr->body); diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 58a30f9a3..e23221337 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -104,6 +104,9 @@ public: void visitIf(If *curr) { shouldBeTrue(curr->condition->type == unreachable || curr->condition->type == i32 || curr->condition->type == i64, curr, "if condition must be valid"); + if (!curr->ifFalse) { + shouldBeFalse(isConcreteWasmType(curr->ifTrue->type), curr, "if without else must not return a value in body"); + } } // override scan to add a pre and a post check task to all nodes |