From 27a841eec6ceb171caae2a2cbd7c92ecdf8d78eb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 1 Mar 2021 15:04:54 +0000 Subject: [Wasm Exceptions] Properly ensure unique Try labels after an inlining (#3632) The old code here just referred to Block and Loop. Refactor it to use the generic helper code that also handles Try. Also add validation of Try names in the validator. The testcase here would have $label appear twice before this fix. After the fix there is $label0 for one of them. --- src/parsing.h | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'src/parsing.h') diff --git a/src/parsing.h b/src/parsing.h index 68647901a..9c3e0cd19 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -22,6 +22,7 @@ #include #include +#include "ir/branch-utils.h" #include "mixed_arena.h" #include "shared-constants.h" #include "support/colors.h" @@ -344,42 +345,32 @@ struct UniqueNameMapper { // Given an expression, ensures all names are unique static void uniquify(Expression* curr) { - struct Walker : public ControlFlowWalker> { + struct Walker + : public ControlFlowWalker> { UniqueNameMapper mapper; static void doPreVisitControlFlow(Walker* self, Expression** currp) { - auto* curr = *currp; - if (auto* block = curr->dynCast()) { - if (block->name.is()) { - block->name = self->mapper.pushLabelName(block->name); + BranchUtils::operateOnScopeNameDefs(*currp, [&](Name& name) { + if (name.is()) { + name = self->mapper.pushLabelName(name); } - } else if (auto* loop = curr->dynCast()) { - if (loop->name.is()) { - loop->name = self->mapper.pushLabelName(loop->name); - } - } + }); } + static void doPostVisitControlFlow(Walker* self, Expression** currp) { - auto* curr = *currp; - if (auto* block = curr->dynCast()) { - if (block->name.is()) { - self->mapper.popLabelName(block->name); - } - } else if (auto* loop = curr->dynCast()) { - if (loop->name.is()) { - self->mapper.popLabelName(loop->name); + BranchUtils::operateOnScopeNameDefs(*currp, [&](Name& name) { + if (name.is()) { + self->mapper.popLabelName(name); } - } + }); } - void visitBreak(Break* curr) { - curr->name = mapper.sourceToUnique(curr->name); - } - void visitSwitch(Switch* curr) { - for (auto& target : curr->targets) { - target = mapper.sourceToUnique(target); - } - curr->default_ = mapper.sourceToUnique(curr->default_); + void visitExpression(Expression* curr) { + BranchUtils::operateOnScopeNameUses(curr, [&](Name& name) { + if (name.is()) { + name = mapper.sourceToUnique(name); + } + }); } }; -- cgit v1.2.3