From f84fa96a0abb482a392040cf0aeab627345d812d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 22 Sep 2017 14:28:11 -0700 Subject: when we re-finalize a function body, we may have changed it from unreachable to none. that is bad if the function has a return value, as unreachable was ok but none is not. in that case, we must add an unreachable (#1193) --- src/ast_utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/ast_utils.h') diff --git a/src/ast_utils.h b/src/ast_utils.h index 95f725636..dfa233f26 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -176,6 +176,15 @@ struct ReFinalize : public WalkerPass> { void visitNop(Nop *curr) { curr->finalize(); } void visitUnreachable(Unreachable *curr) { curr->finalize(); } + void visitFunction(Function* curr) { + // we may have changed the body from unreachable to none, which might be bad + // if the function has a return value + if (curr->result != none && curr->body->type == none) { + Builder builder(*getModule()); + curr->body = builder.blockify(curr->body, builder.makeUnreachable()); + } + } + WasmType getValueType(Expression* value) { return value ? value->type : none; } -- cgit v1.2.3