diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/names.h | 8 | ||||
-rw-r--r-- | src/wasm-ir-builder.h | 10 | ||||
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/ir/names.h b/src/ir/names.h index e2a168940..c10b70b52 100644 --- a/src/ir/names.h +++ b/src/ir/names.h @@ -49,12 +49,14 @@ inline void ensureNames(Function* func) { // name will begin there. This can be used to avoid trying the same 0,1,2,.. // etc. names each time (which could lead to quadratic behavior in certain // cases). -inline Name -getValidName(Name root, std::function<bool(Name)> check, Index hint = 0) { +inline Name getValidName(Name root, + std::function<bool(Name)> check, + Index hint = 0, + std::string separator = "_") { if (check(root)) { return root; } - auto prefixed = std::string(root.str) + '_'; + auto prefixed = std::string(root.str) + separator; Index num = hint; while (1) { auto name = prefixed + std::to_string(num); diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 3b6588e86..5803f0c61 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -461,9 +461,13 @@ private: std::unordered_map<Name, std::vector<Index>> labelDepths; Name makeFresh(Name label) { - return Names::getValidName(label, [&](Name candidate) { - return labelDepths.insert({candidate, {}}).second; - }); + return Names::getValidName( + label, + [&](Name candidate) { + return labelDepths.insert({candidate, {}}).second; + }, + 0, + ""); } void pushScope(ScopeCtx scope) { diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index bee858435..78ce07f8d 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1035,7 +1035,11 @@ Result<Name> IRBuilder::getLabelName(Index label) { auto& scopeLabel = (*scope)->label; if (!scopeLabel) { // The scope does not already have a name, so we need to create one. - scopeLabel = makeFresh("label"); + if ((*scope)->getBlock()) { + scopeLabel = makeFresh("block"); + } else { + scopeLabel = makeFresh("label"); + } } (*scope)->labelUsed = true; return scopeLabel; |