From 91ec2ee5bedefc4736fcda78ae39298846aeeb41 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 11 May 2020 10:50:11 -0700 Subject: Handle throw and rethrow in DCE (#2844) This adds missing handlings for `throw` and `rethrow` in DCE. They should set `reachable` variable to `false`, like other branches. --- src/passes/DeadCodeElimination.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp index ebeeca364..400252e8f 100644 --- a/src/passes/DeadCodeElimination.cpp +++ b/src/passes/DeadCodeElimination.cpp @@ -148,14 +148,6 @@ struct DeadCodeElimination reachable = false; } - void visitBrOnExn(BrOnExn* curr) { - if (isDead(curr->exnref)) { - replaceCurrent(curr->exnref); - return; - } - addBreak(curr->name); - } - void visitReturn(Return* curr) { if (isDead(curr->value)) { replaceCurrent(curr->value); @@ -259,6 +251,18 @@ struct DeadCodeElimination typeUpdater.maybeUpdateTypeToUnreachable(curr); } + void visitThrow(Throw* curr) { reachable = false; } + + void visitRethrow(Rethrow* curr) { reachable = false; } + + void visitBrOnExn(BrOnExn* curr) { + if (isDead(curr->exnref)) { + replaceCurrent(curr->exnref); + return; + } + addBreak(curr->name); + } + static void scan(DeadCodeElimination* self, Expression** currp) { auto* curr = *currp; if (!self->reachable) { -- cgit v1.2.3