diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-08-28 14:36:22 -0700 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-08-28 14:36:22 -0700 |
commit | d199aafed128cdf52de229aba4cf4c6769929e71 (patch) | |
tree | 61bf42460ee32fc37a57ac187fac834510e21b99 /src | |
parent | 3c8be1c57c3c30168d795e46a4389ec878156215 (diff) | |
download | binaryen-d199aafed128cdf52de229aba4cf4c6769929e71.tar.gz binaryen-d199aafed128cdf52de229aba4cf4c6769929e71.tar.bz2 binaryen-d199aafed128cdf52de229aba4cf4c6769929e71.zip |
fix an inlining bug where a void function has an unreachable body
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Inlining.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 710fc00ff..192480d26 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -155,7 +155,6 @@ static Expression* doInlining(Module* module, Function* into, InliningAction& ac auto* call = (*action.callSite)->cast<Call>(); Builder builder(*module); auto* block = Builder(*module).makeBlock(); - block->type = call->type; block->name = Name(std::string("__inlined_func$") + from->name.str); *action.callSite = block; // set up a locals mapping @@ -191,6 +190,16 @@ static Expression* doInlining(Module* module, Function* into, InliningAction& ac auto* contents = ExpressionManipulator::copy(from->body, *module); updater.walk(contents); block->list.push_back(contents); + block->type = call->type; + // if the function returned a value, we just set the block containing the + // inlined code to have that type. or, if the function was void and + // contained void, that is fine too. a bad case is a void function in which + // we have unreachable code, so we would be replacing a void call with an + // unreachable; we need to handle + if (contents->type == unreachable && block->type == none) { + // make the block reachable by adding a break to it + block->list.push_back(builder.makeBreak(block->name)); + } return block; } |