summaryrefslogtreecommitdiff
path: root/src/passes/ReReloop.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-11-09 15:09:34 -0800
committerGitHub <noreply@github.com>2017-11-09 15:09:34 -0800
commit566e2c15016cbcf45dfa844ef2788ce27cdfab6f (patch)
tree645c96ac9e50e37d2d237cde747b1030f6501657 /src/passes/ReReloop.cpp
parent83f62325ac33706b1fcc589bc5ad6e290ed14d3f (diff)
downloadbinaryen-566e2c15016cbcf45dfa844ef2788ce27cdfab6f.tar.gz
binaryen-566e2c15016cbcf45dfa844ef2788ce27cdfab6f.tar.bz2
binaryen-566e2c15016cbcf45dfa844ef2788ce27cdfab6f.zip
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.
Diffstat (limited to 'src/passes/ReReloop.cpp')
-rw-r--r--src/passes/ReReloop.cpp12
1 files changed, 12 insertions, 0 deletions
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);