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 | |
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
-rw-r--r-- | src/passes/Inlining.cpp | 11 | ||||
-rw-r--r-- | test/passes/inlining-optimizing.txt | 8 | ||||
-rw-r--r-- | test/passes/inlining-optimizing.wast | 9 |
3 files changed, 27 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; } diff --git a/test/passes/inlining-optimizing.txt b/test/passes/inlining-optimizing.txt index e1f81e54f..19c580063 100644 --- a/test/passes/inlining-optimizing.txt +++ b/test/passes/inlining-optimizing.txt @@ -33,3 +33,11 @@ (nop) ) ) +(module + (type $0 (func (result i32))) + (type $1 (func)) + (memory $0 0) + (func $main (type $0) (result i32) + (unreachable) + ) +) diff --git a/test/passes/inlining-optimizing.wast b/test/passes/inlining-optimizing.wast index 082c4e98a..4f4f348a6 100644 --- a/test/passes/inlining-optimizing.wast +++ b/test/passes/inlining-optimizing.wast @@ -76,4 +76,13 @@ (drop (get_local $z)) ) ) +(module + (func $main (result i32) + (call $func_51) + (i32.const 0) + ) + (func $func_51 + (unreachable) ;; void function but having unreachable body, when inlined, type must be fixed + ) +) |