diff options
-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 + ) +) |