Skip to content

Commit 0c0fc3b

Browse files
HerrCai0907atc-github
authored andcommitted
fix(gc.merge_ssa): handle the nullopt for unreachable AS code (#117)
1 parent 731cdb5 commit 0c0fc3b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

passes/GC/MergeSSA.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cassert>
22
#include <cstddef>
33
#include <map>
4+
#include <optional>
45

56
#include "MergeSSA.hpp"
67
#include "SSAObj.hpp"
@@ -53,7 +54,13 @@ void MergeSSA::runOnFunction(wasm::Module *m, wasm::Function *func) {
5354
if (auto *const getExpr = callExpr->operands[0]->dynCast<wasm::LocalGet>()) {
5455
// this tmp ssa is reference of local
5556
wasm::Index const localIndex = getExpr->index;
56-
Liveness const localgetLiveness = livenessMap.getLiveness(getExpr).value();
57+
std::optional<Liveness> const liveness = livenessMap.getLiveness(getExpr);
58+
if (liveness == std::nullopt)
59+
// this expr are unreachable, so CFG will not contain it.
60+
// we just skip this node and let other optimization handle it.
61+
// FIXME: maybe we should do pre-opt to remove the dead code?
62+
continue;
63+
Liveness const localgetLiveness = liveness.value();
5764

5865
DynBitset const localMappedSSA = localIndexToSSA.get(localIndex);
5966
DynBitset const livenessBeforeLocalGet = localgetLiveness.before() & localMappedSSA;

0 commit comments

Comments
 (0)