From c4d15efc62fb6e6b55dd128e62896c93ca52c98a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 15 Feb 2023 13:05:25 -0800 Subject: Unreachability fixes for inlining (#5492) We must refinalize as inlining unreachable code can lead to more things becoming unreachable. We also must uniquify label names before refinalizing, as the IR must be valid at that time, so that code is moved. This causes some minor changes to existing test code (some label changes, and refinalization makes more things unreachable), but only the two new tests show actual problems that needed to be fixed. --- src/passes/Inlining.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 4475db7b0..7df5c8f29 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -413,6 +413,16 @@ static Expression* doInlining(Module* module, // Make the block reachable by adding a break to it block->list.push_back(builder.makeBreak(block->name)); } + // Anything we inlined into may now have non-unique label names, fix it up. + // Note that we must do this before refinalization, as otherwise duplicate + // block labels can lead to errors (the IR must be valid before we + // refinalize). + wasm::UniqueNameMapper::uniquify(into->body); + // Inlining unreachable contents can make things in the function we inlined + // into unreachable. + ReFinalize().walkFunctionInModule(into, module); + // New locals we added may require fixups for nondefaultability. + // FIXME Is this not done automatically? TypeUpdating::handleNonDefaultableLocals(into, *module); return block; } @@ -1039,11 +1049,6 @@ struct Inlining : public Pass { assert(inlinedUses[inlinedName] <= infos[inlinedName].refs); } } - for (auto func : inlinedInto) { - // Anything we inlined into may now have non-unique label names, fix it - // up. - wasm::UniqueNameMapper::uniquify(func->body); - } if (optimize && inlinedInto.size() > 0) { OptUtils::optimizeAfterInlining(inlinedInto, module, getPassRunner()); } -- cgit v1.2.3