Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug with unreachable control flow in IRBuilder #6558

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {

ScopeCtx() : scope(NoScope{}) {}
ScopeCtx(Scope scope) : scope(scope) {}
ScopeCtx(Scope scope, Name label) : scope(scope), label(label) {}
ScopeCtx(Scope scope, Name label, Name branchLabel)
: scope(scope), label(label), branchLabel(branchLabel) {}
ScopeCtx(Scope scope, Name label, bool labelUsed)
: scope(scope), label(label), labelUsed(labelUsed) {}
ScopeCtx(Scope scope, Name label, bool labelUsed, Name branchLabel)
: scope(scope), label(label), branchLabel(branchLabel),
labelUsed(labelUsed) {}

static ScopeCtx makeFunc(Function* func) {
return ScopeCtx(FuncScope{func});
Expand All @@ -324,20 +326,29 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
static ScopeCtx makeIf(If* iff, Name originalLabel = {}) {
return ScopeCtx(IfScope{iff, originalLabel});
}
static ScopeCtx makeElse(If* iff, Name originalLabel, Name label) {
return ScopeCtx(ElseScope{iff, originalLabel}, label);
static ScopeCtx
makeElse(If* iff, Name originalLabel, Name label, bool labelUsed) {
return ScopeCtx(ElseScope{iff, originalLabel}, label, labelUsed);
}
static ScopeCtx makeLoop(Loop* loop) { return ScopeCtx(LoopScope{loop}); }
static ScopeCtx makeTry(Try* tryy, Name originalLabel = {}) {
return ScopeCtx(TryScope{tryy, originalLabel});
}
static ScopeCtx
makeCatch(Try* tryy, Name originalLabel, Name label, Name branchLabel) {
return ScopeCtx(CatchScope{tryy, originalLabel}, label, branchLabel);
static ScopeCtx makeCatch(Try* tryy,
Name originalLabel,
Name label,
bool labelUsed,
Name branchLabel) {
return ScopeCtx(
CatchScope{tryy, originalLabel}, label, labelUsed, branchLabel);
}
static ScopeCtx
makeCatchAll(Try* tryy, Name originalLabel, Name label, Name branchLabel) {
return ScopeCtx(CatchAllScope{tryy, originalLabel}, label, branchLabel);
static ScopeCtx makeCatchAll(Try* tryy,
Name originalLabel,
Name label,
bool labelUsed,
Name branchLabel) {
return ScopeCtx(
CatchAllScope{tryy, originalLabel}, label, labelUsed, branchLabel);
}
static ScopeCtx makeTryTable(TryTable* trytable, Name originalLabel = {}) {
return ScopeCtx(TryTableScope{trytable, originalLabel});
Expand Down
11 changes: 8 additions & 3 deletions src/wasm/wasm-ir-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,11 @@ Result<> IRBuilder::visitElse() {
}
auto originalLabel = scope.getOriginalLabel();
auto label = scope.label;
auto labelUsed = scope.labelUsed;
auto expr = finishScope();
CHECK_ERR(expr);
iff->ifTrue = *expr;
pushScope(ScopeCtx::makeElse(iff, originalLabel, label));
pushScope(ScopeCtx::makeElse(iff, originalLabel, label, labelUsed));
return Ok{};
}

Expand All @@ -830,6 +831,7 @@ Result<> IRBuilder::visitCatch(Name tag) {
}
auto originalLabel = scope.getOriginalLabel();
auto label = scope.label;
auto labelUsed = scope.labelUsed;
auto branchLabel = scope.branchLabel;
auto expr = finishScope();
CHECK_ERR(expr);
Expand All @@ -839,7 +841,8 @@ Result<> IRBuilder::visitCatch(Name tag) {
tryy->catchBodies.push_back(*expr);
}
tryy->catchTags.push_back(tag);
pushScope(ScopeCtx::makeCatch(tryy, originalLabel, label, branchLabel));
pushScope(
ScopeCtx::makeCatch(tryy, originalLabel, label, labelUsed, branchLabel));
// Push a pop for the exception payload.
auto params = wasm.getTag(tag)->sig.params;
if (params != Type::none) {
Expand All @@ -861,6 +864,7 @@ Result<> IRBuilder::visitCatchAll() {
}
auto originalLabel = scope.getOriginalLabel();
auto label = scope.label;
auto labelUsed = scope.labelUsed;
auto branchLabel = scope.branchLabel;
auto expr = finishScope();
CHECK_ERR(expr);
Expand All @@ -869,7 +873,8 @@ Result<> IRBuilder::visitCatchAll() {
} else {
tryy->catchBodies.push_back(*expr);
}
pushScope(ScopeCtx::makeCatchAll(tryy, originalLabel, label, branchLabel));
pushScope(
ScopeCtx::makeCatchAll(tryy, originalLabel, label, labelUsed, branchLabel));
return Ok{};
}

Expand Down
Loading
Loading