From 566e2c15016cbcf45dfa844ef2788ce27cdfab6f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 9 Nov 2017 15:09:34 -0800 Subject: Rereloop fuzz fix (#1259) * fix relooper bug, ensure function body has right type, as relooper output does not flow stuff out, but wasm functions with a result do expect a flow value, so none is not an option. in other words, as the docs say, a relooper block must end with a terminator (return, unreachable, break, etc.) and not flow out. --- src/passes/ReReloop.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/passes/ReReloop.cpp b/src/passes/ReReloop.cpp index 99e60a72f..ff1eec6b5 100644 --- a/src/passes/ReReloop.cpp +++ b/src/passes/ReReloop.cpp @@ -345,6 +345,18 @@ struct ReReloop final : public Pass { auto temp = builder->addVar(function, i32); CFG::RelooperBuilder builder(*module, temp); function->body = relooper.Render(builder); + // if the function has a result, and the relooper emitted + // something that seems like it flows out without a value + // (but that path is never reached; it just has a br to it + // because of the relooper's boilerplate switch-handling + // code, for example, which could be optimized out later + // but isn't yet), then make sure it has a proper type + if (function->result != none && function->body->type == none) { + function->body = builder.makeSequence( + function->body, + builder.makeUnreachable() + ); + } } // TODO: should this be in the relooper itself? ReFinalize().walk(function->body); -- cgit v1.2.3