From cde2830e44a3248d0f2d9750f180635c0465a579 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 2 Aug 2021 11:38:50 -0700 Subject: [Wasm GC] Handle unreachability in LocalSubtyping (#4044) --- src/passes/LocalSubtyping.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/passes/LocalSubtyping.cpp b/src/passes/LocalSubtyping.cpp index ae197858c..19ce2f275 100644 --- a/src/passes/LocalSubtyping.cpp +++ b/src/passes/LocalSubtyping.cpp @@ -102,6 +102,7 @@ struct LocalSubtyping : public WalkerPass> { // TODO: handle cycles of X -> Y -> X etc. bool more; + bool optimized = false; do { more = false; @@ -150,6 +151,7 @@ struct LocalSubtyping : public WalkerPass> { assert(Type::isSubType(newType, oldType)); func->vars[i - varBase] = newType; more = true; + optimized = true; // Update gets and tees. for (auto* get : getsForLocal[i]) { @@ -167,6 +169,24 @@ struct LocalSubtyping : public WalkerPass> { } } } while (more); + + // If we ever optimized, then we also need to do a final pass to update any + // unreachable gets and tees. They are not seen or updated in the above + // analysis, but must be fixed up for validation to work. + if (optimized) { + for (auto* get : FindAll(func->body).list) { + get->type = func->getLocalType(get->index); + } + for (auto* set : FindAll(func->body).list) { + if (set->isTee()) { + set->type = func->getLocalType(set->index); + set->finalize(); + } + } + + // Also update their parents. + ReFinalize().walkFunctionInModule(func, getModule()); + } } }; -- cgit v1.2.3