From b279a0af237f6db5a0b6262686fd79d9a0f39888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 15 Sep 2026 16:05:16 +0200 Subject: [PATCH 1/5] Read label names from the name section Read label names, and use the names when building the IR. Blocks and loops can hold names directly. `if`, `try` and `try_table` cannot, so for them the name is only a hint: we use it when a branch to the scope means we have to create a wrapper block anyhow, and otherwise drop it, so that reading these names never changes the shape of the IR. --- src/wasm-binary.h | 16 ++- src/wasm-ir-builder.h | 12 +++ src/wasm/wasm-binary.cpp | 91 ++++++++++++++++-- src/wasm/wasm-ir-builder.cpp | 13 ++- test/lit/binary/label-names-bad-index.test | 13 +++ .../binary/label-names-bad-index.test.wasm | Bin 0 -> 196 bytes test/lit/binary/label-names.test | 78 +++++++++++++++ test/lit/binary/label-names.test.wasm | Bin 0 -> 196 bytes 8 files changed, 210 insertions(+), 13 deletions(-) create mode 100644 test/lit/binary/label-names-bad-index.test create mode 100644 test/lit/binary/label-names-bad-index.test.wasm create mode 100644 test/lit/binary/label-names.test create mode 100644 test/lit/binary/label-names.test.wasm diff --git a/src/wasm-binary.h b/src/wasm-binary.h index eb53aab8703..2e45e0db55f 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1721,13 +1721,16 @@ class WasmBinaryReader { Signature getSignatureByTypeIndex(Index index); Signature getSignatureByFunctionIndex(Index index); - Name getNextLabel(); - // We read the names section first so we know in advance what names various // elements should have. Store the information for use when building // expressions. std::unordered_map functionNames; std::unordered_map> localNames; + // Label names, indexed by function index and then by the index of the label + // in the function. Labels are indexed in the order the instructions that + // introduce them appear in the function body, including the ones that have + // no name in the name section. + std::unordered_map> labelNames; std::unordered_map typeNames; std::unordered_map> fieldNames; std::unordered_map tableNames; @@ -1743,6 +1746,14 @@ class WasmBinaryReader { usedGlobalNames, usedTagNames; Function* currFunction = nullptr; + // The label names of the function we are currently reading, if it has any, + // and the index of the next label in it. + const std::unordered_map* currLabelNames = nullptr; + Index nextLabelIndex = 0; + + // Returns the name the name section gives to the next label of the current + // function, or a null name if it has none, and advances the label index. + Name getNextLabelName(); // before we see a function (like global init expressions), there is no end of // function to check Index endOfFunction = -1; @@ -1753,6 +1764,7 @@ class WasmBinaryReader { void readFunctions(); void readVars(); void setLocalNames(Function& func, Index i); + void setLabelNames(Index i); Result<> readInst(); diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index a5f3ccdb9ad..7c1cf6b63d1 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -105,6 +105,13 @@ class IRBuilder : public UnifiedExpressionVisitor> { Type inputType = Type::none); Result<> visitEnd(); + // Set the name to use for the label of the scope we are currently building, + // if that scope ends up needing a label. This is used for names that come + // from the binary name section, which are optional: unlike names parsed from + // the text format, they should not cause us to introduce blocks that would + // not otherwise exist just to have something to hold the name. + void setScopeNameHint(Name name); + // Used to visit break nodes when traversing a single block without its // context. The type indicates how many values the break carries to its // destination. @@ -414,6 +421,11 @@ class IRBuilder : public UnifiedExpressionVisitor> { // for branches, since the normal label is only used for delegates. Name branchLabel; + // The name to use if we end up needing a label for this scope. Unlike + // `label`, this does not itself cause the scope to be labeled. See + // `setScopeNameHint`. + Name nameHint; + bool labelUsed = false; // If the control flow scope has an input type, we need to lower it using a diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index fa857fd8307..ad8fce91f52 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3358,6 +3358,25 @@ void WasmBinaryReader::setLocalNames(Function& func, Index i) { } } +void WasmBinaryReader::setLabelNames(Index i) { + if (auto it = labelNames.find(i); it != labelNames.end()) { + currLabelNames = &it->second; + } else { + currLabelNames = nullptr; + } + nextLabelIndex = 0; +} + +Name WasmBinaryReader::getNextLabelName() { + auto index = nextLabelIndex++; + if (currLabelNames) { + if (auto it = currLabelNames->find(index); it != currLabelNames->end()) { + return it->second; + } + } + return Name(); +} + void WasmBinaryReader::readFunctionSignatures() { size_t num = getU32LEB(); auto numImports = wasm.functions.size(); @@ -3376,6 +3395,14 @@ void WasmBinaryReader::readFunctionSignatures() { << index << '\n'; } } + // Likewise for the label names subsection. + for (auto& [index, labels] : labelNames) { + if (index >= num + numImports) { + std::cerr << "warning: function index out of bounds in name section: " + "labels at index " + << index << '\n'; + } + } for (size_t i = 0; i < num; i++) { auto [name, isExplicit] = getOrMakeName( functionNames, numImports + i, makeName("", i), usedFunctionNames); @@ -3452,6 +3479,7 @@ void WasmBinaryReader::readFunctions() { readVars(); setLocalNames(*func, numFuncImports + i); + setLabelNames(numFuncImports + i); { // Process the function body. Even if we are skipping function bodies we // need to not skip the start function. That contains important code for @@ -3485,12 +3513,25 @@ void WasmBinaryReader::readFunctions() { if (!builder.empty()) { throwError("expected function end"); } + if (currLabelNames) { + // Check that the labels named in the name section actually exist. + Index maxIndex = 0; + for (auto& [index, name] : *currLabelNames) { + maxIndex = std::max(maxIndex, index); + } + if (maxIndex >= nextLabelIndex) { + std::cerr << "warning: label index out of bounds in name section: " + << maxIndex << " in function " << (numFuncImports + i) + << '\n'; + } + } } } sourceMapReader.finishFunction(); TypeUpdating::handleNonDefaultableLocals(func.get(), wasm); currFunction = nullptr; + currLabelNames = nullptr; } } @@ -3543,12 +3584,22 @@ Result<> WasmBinaryReader::readInst() { } uint8_t code = getInt8(); switch (code) { - case BinaryConsts::Block: - return builder.makeBlock(Name(), getBlockType()); - case BinaryConsts::If: - return builder.makeIf(Name(), getBlockType()); - case BinaryConsts::Loop: - return builder.makeLoop(Name(), getBlockType()); + case BinaryConsts::Block: { + auto name = getNextLabelName(); + return builder.makeBlock(name, getBlockType()); + } + case BinaryConsts::If: { + // An `if` cannot hold a name in Binaryen IR, so only use the name if we + // end up needing a label anyhow. + auto name = getNextLabelName(); + auto result = builder.makeIf(Name(), getBlockType()); + builder.setScopeNameHint(name); + return result; + } + case BinaryConsts::Loop: { + auto name = getNextLabelName(); + return builder.makeLoop(name, getBlockType()); + } case BinaryConsts::Br: return builder.makeBreak(getU32LEB(), false); case BinaryConsts::BrIf: @@ -3636,9 +3687,16 @@ Result<> WasmBinaryReader::readInst() { return builder.makeTableGet(getTableName(getU32LEB())); case BinaryConsts::TableSet: return builder.makeTableSet(getTableName(getU32LEB())); - case BinaryConsts::Try: - return builder.makeTry(Name(), getBlockType()); + case BinaryConsts::Try: { + // As with `if`, only use the name if we end up needing a label. + auto name = getNextLabelName(); + auto result = builder.makeTry(Name(), getBlockType()); + builder.setScopeNameHint(name); + return result; + } case BinaryConsts::TryTable: { + // As with `if`, only use the name if we end up needing a label. + auto name = getNextLabelName(); auto type = getBlockType(); std::vector tags; std::vector labels; @@ -3655,7 +3713,9 @@ Result<> WasmBinaryReader::readInst() { isRefs.push_back(code == BinaryConsts::CatchRef || code == BinaryConsts::CatchAllRef); } - return builder.makeTryTable(Name(), type, tags, labels, isRefs); + auto result = builder.makeTryTable(Name(), type, tags, labels, isRefs); + builder.setScopeNameHint(name); + return result; } case BinaryConsts::Throw: return builder.makeThrow(getTagName(getU32LEB())); @@ -5476,6 +5536,19 @@ void WasmBinaryReader::readNames(size_t sectionPos, size_t payloadLen) { localNames[funcIndex][localIndex] = name; } } + } else if (nameType == Subsection::NameLabel) { + auto numFuncs = getU32LEB(); + for (size_t i = 0; i < numFuncs; i++) { + auto funcIndex = getU32LEB(); + auto numLabels = getU32LEB(); + NameProcessor processor; + for (size_t j = 0; j < numLabels; j++) { + auto labelIndex = getU32LEB(); + auto rawName = getInlineString(); + auto name = processor.process(rawName); + labelNames[funcIndex][labelIndex] = name; + } + } } else if (nameType == Subsection::NameType) { auto num = getU32LEB(); NameProcessor processor; diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index bdc0da8fad2..30bec274fcf 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1445,8 +1445,11 @@ Result IRBuilder::getLabelName(Index label, bool forDelegate) { useTryBranchLabel ? (*scope)->branchLabel : (*scope)->label; if (!scopeLabel) { - // The scope does not already have a name, so we need to create one. - if ((*scope)->getBlock()) { + // The scope does not already have a name, so we need to create one. Use the + // name from the name section, if we have one. + if (auto hint = (*scope)->nameHint) { + scopeLabel = makeFresh(hint); + } else if ((*scope)->getBlock()) { scopeLabel = makeFresh("block", blockHint++); } else { scopeLabel = makeFresh("label", labelHint++); @@ -1458,6 +1461,12 @@ Result IRBuilder::getLabelName(Index label, bool forDelegate) { return scopeLabel; } +void IRBuilder::setScopeNameHint(Name name) { + if (!scopeStack.empty()) { + scopeStack.back().nameHint = name; + } +} + Result<> IRBuilder::makeNop() { push(builder.makeNop()); return Ok{}; diff --git a/test/lit/binary/label-names-bad-index.test b/test/lit/binary/label-names-bad-index.test new file mode 100644 index 00000000000..c6f393ae538 --- /dev/null +++ b/test/lit/binary/label-names-bad-index.test @@ -0,0 +1,13 @@ +;; RUN: wasm-opt -all %s.wasm -q -S -o - 2>&1 | filecheck %s + +;; This is label-names.test.wasm with the label index of $used-try-table in the +;; name section changed from 7 to 99, which is past the end of the function's +;; label index space. We should warn and ignore that name, but otherwise read +;; the module normally. + +;; CHECK: warning: label index out of bounds in name section: 99 in function 0 + +;; CHECK: (block $handler +;; CHECK-NEXT: (block $label +;; CHECK-NEXT: (try_table (catch_all $handler) +;; CHECK-NEXT: (br $label) diff --git a/test/lit/binary/label-names-bad-index.test.wasm b/test/lit/binary/label-names-bad-index.test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..7aae8e6bbe074e73939c0b0751554aa36c054669 GIT binary patch literal 196 zcmXwyOAdlS5JanIMhG-`1zDSr7*BwwaLWKgBo3eOS-9fr4k(+hs`nNRJ+%aY0+9nb zt+Yx(6iWxgJKZ2wnI(w9;s{QlvIu*S!7Hz literal 0 HcmV?d00001 diff --git a/test/lit/binary/label-names.test b/test/lit/binary/label-names.test new file mode 100644 index 00000000000..828a84e9cca --- /dev/null +++ b/test/lit/binary/label-names.test @@ -0,0 +1,78 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: wasm-opt -all %s.wasm -q -S -o - | filecheck %s + +;; Test that we read label names from the name section. The wasm file was +;; produced by wasm-tools from +;; +;; (module +;; (tag $e) +;; (func $f (param $p i32) (result i32) +;; (block $named-block (result i32) +;; (loop $named-loop +;; (br_if $named-loop (local.get $p)) +;; ) +;; (block ;; unnamed: still takes a label index +;; (br_if 0 (local.get $p)) +;; ) +;; (block $unused-block) +;; (if $used-if (local.get $p) (then (br $used-if))) +;; (if $unused-if (local.get $p) (then (nop))) +;; (block $handler +;; (try_table $used-try-table (catch_all $handler) +;; (br $used-try-table) +;; ) +;; ) +;; (i32.const 42) +;; ) +;; ) +;; ) +;; +;; The unnamed block takes label index 2, so reading the names of the labels +;; after it depends on counting it. `if` and `try_table` cannot hold names in +;; Binaryen IR, so their names are only used when they are branched to, which +;; requires a wrapper block anyhow: $used-if and $used-try-table are preserved, +;; while $unused-if is dropped rather than introducing a block for it. +;; CHECK: (type $0 (func)) + +;; CHECK: (type $1 (func (param i32) (result i32))) + +;; CHECK: (tag $e (type $0)) + +;; CHECK: (func $f (type $1) (param $p i32) (result i32) +;; CHECK-NEXT: (block $named-block (result i32) +;; CHECK-NEXT: (loop $named-loop +;; CHECK-NEXT: (br_if $named-loop +;; CHECK-NEXT: (local.get $p) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block $block +;; CHECK-NEXT: (br_if $block +;; CHECK-NEXT: (local.get $p) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block $unused-block +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block $used-if +;; CHECK-NEXT: (if +;; CHECK-NEXT: (local.get $p) +;; CHECK-NEXT: (then +;; CHECK-NEXT: (br $used-if) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (if +;; CHECK-NEXT: (local.get $p) +;; CHECK-NEXT: (then +;; CHECK-NEXT: (nop) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (block $handler +;; CHECK-NEXT: (block $used-try-table +;; CHECK-NEXT: (try_table (catch_all $handler) +;; CHECK-NEXT: (br $used-try-table) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: (i32.const 42) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) diff --git a/test/lit/binary/label-names.test.wasm b/test/lit/binary/label-names.test.wasm new file mode 100644 index 0000000000000000000000000000000000000000..21d01d785addf65332623f7423ca5d27e035baef GIT binary patch literal 196 zcmXwyOAdlS5JanIMkdhU6=ZEfVmtw!!YzXgkvM$9XW@#gJD_g5s@_{P%+wM93Pk}F zw9+aCQ6fEzu5^J|Wu77di+^wmmB-kFJU-H5cuqVI5hKgf9Lmg#Sl-g{FY!XIwxKtD}aIXmj(F6Z%`&8Bpgw>S0!ST83+ literal 0 HcmV?d00001 From 01f273767216993a813f08ca8a1f3c430b250b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Thu, 17 Sep 2026 11:48:42 +0200 Subject: [PATCH 2/5] Write label names to the name section Write the label subsection (id 3) next to the function and local names when debug info is enabled. Only explicit names are written: the ones that came from the text format, from the name section, or through the C API, and not the ones we generate ourselves. Functions therefore gain an `explicitLabelNames` set, filled by IRBuilder when a label comes from outside rather than from makeFresh(). Keeping this next to `localNames` and `debugLocations` rather than on the expressions themselves is how the rest of our debug info is stored, and it has two advantages: ExpressionAnalyzer never sees it, so two otherwise-identical blocks cannot stop comparing equal because of debug info; and since label names are unique within a function, it keeps identifying the right labels as optimizations replace the expressions that carry them. --- src/binaryen-c.cpp | 23 ++ src/ir/module-utils.cpp | 1 + src/wasm-binary.h | 8 + src/wasm-ir-builder.h | 30 +- src/wasm-stack.h | 18 ++ src/wasm.h | 10 + src/wasm/wasm-binary.cpp | 41 +++ src/wasm/wasm-ir-builder.cpp | 23 +- src/wasm/wasm-stack.cpp | 16 + src/wasm/wasm.cpp | 5 +- test/example/c-api-unused-mem.txt | 6 +- test/lit/basic/custom-descriptors.wast | 20 +- test/lit/basic/exception-handling-legacy.wast | 96 +++--- test/lit/basic/exception-handling-no-gc.wast | 4 +- test/lit/basic/exception-handling.wast | 88 +++--- .../lit/basic/fn_prolog_epilog.debugInfo.wast | 6 +- test/lit/basic/min.wast | 14 +- test/lit/basic/polymorphic_stack.wast | 40 ++- test/lit/basic/reference-types.wast | 32 +- test/lit/basic/reg_switch.wast | 4 +- test/lit/basic/stack_switching.wast | 32 +- test/lit/basic/stack_switching_resume.wast | 4 +- .../basic/stack_switching_resume_throw.wast | 4 +- test/lit/basic/types-function-references.wast | 2 +- test/lit/basic/unit.wat | 92 +++--- test/lit/basic/unreachable-code.wast | 10 +- test/lit/basic/untaken-br_if.wast | 8 +- test/lit/binary/label-names-write.wast | 292 ++++++++++++++++++ test/lit/blocktype.wast | 6 +- test/lit/br_if_cont_uncastable.wast | 16 +- test/lit/branch-hinting.wast | 48 +-- test/lit/cast-and-recast-tuple.wast | 20 +- test/lit/cast-and-recast.wast | 28 +- test/lit/cast-to-basic.wast | 12 +- test/lit/downgrade-reftypes.wast | 16 +- test/lit/multi-hints.wast | 8 +- test/lit/multivalue.wast | 16 +- ...asyncify_pass-arg=asyncify-eh-asserts.wast | 18 +- test/lit/passes/code-pushing-eh-legacy.wast | 2 +- test/lit/passes/gufa-refs.wast | 2 +- test/lit/passes/inlining-eh-legacy.wast | 6 +- test/lit/passes/once-reduction.wast | 2 +- test/lit/passes/roundtrip.wast | 2 +- test/lit/passes/rse-eh-legacy.wast | 2 +- test/lit/passes/signature-pruning.wast | 4 +- test/lit/passes/stack-ir-eh-legacy.wast | 2 +- test/lit/passes/vacuum-tnh.wast | 4 +- test/lit/reftypes-without-gc.wast | 4 +- test/lit/source-map.wast | 6 +- test/lit/wat-kitchen-sink.wast | 20 +- 50 files changed, 820 insertions(+), 353 deletions(-) create mode 100644 test/lit/binary/label-names-write.wast diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 53748beef9d..ecb803d0c68 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -5537,6 +5537,27 @@ void BinaryenStringSliceWTFSetEnd(BinaryenExpressionRef expr, // Functions +// Every label name in a body built through the C API was given to us by the +// caller, so all of them are explicit. +static void noteExplicitLabelNames(Function* func) { + if (!func->body) { + return; + } + struct Scanner : public PostWalker { + std::unordered_set& names; + Scanner(std::unordered_set& names) : names(names) {} + void note(Name name) { + if (name) { + names.insert(name); + } + } + void visitBlock(Block* curr) { note(curr->name); } + void visitLoop(Loop* curr) { note(curr->name); } + void visitTry(Try* curr) { note(curr->name); } + } scanner(func->explicitLabelNames); + scanner.walk(func->body); +} + static BinaryenFunctionRef addFunctionInternal(BinaryenModuleRef module, const char* name, HeapType type, @@ -5550,6 +5571,7 @@ static BinaryenFunctionRef addFunctionInternal(BinaryenModuleRef module, ret->vars.push_back(Type(varTypes[i])); } ret->body = (Expression*)body; + noteExplicitLabelNames(ret); // Lock. This can be called from multiple threads at once, and is a // point where they all access and modify the module. @@ -6594,6 +6616,7 @@ void BinaryenFunctionSetBody(BinaryenFunctionRef func, BinaryenExpressionRef body) { assert(body); ((Function*)func)->body = (Expression*)body; + noteExplicitLabelNames((Function*)func); } BinaryenHeapType BinaryenFunctionGetType(BinaryenFunctionRef func) { return ((Function*)func)->type.getHeapType().getID(); diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index 46dd332e102..af8f3e9ff66 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -74,6 +74,7 @@ copyFunctionWithoutAdd(Function* func, ret->vars = func->vars; ret->localNames = func->localNames; ret->localIndices = func->localIndices; + ret->explicitLabelNames = func->explicitLabelNames; ret->body = ExpressionManipulator::copy(func->body, out); metadata::copyBetweenFunctions(func->body, ret->body, func, ret.get()); ret->funcAnnotations = func->funcAnnotations; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 2e45e0db55f..99aef564b7c 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1438,6 +1438,8 @@ class WasmBinaryWriter { void writeFunctionSignatures(); void writeExpression(Expression* curr); void writeFunctions(); + void noteLabelNames(Function* func, + std::vector>& labelNames); void writeStrings(); void writeGlobals(); void writeExports(); @@ -1506,6 +1508,7 @@ class WasmBinaryWriter { }; Module* getModule() { return wasm; } + bool getDebugInfo() const { return debugInfo; } void writeType(Type type); @@ -1569,6 +1572,11 @@ class WasmBinaryWriter { // info here, and then use it when writing the names. std::unordered_map funcMappedLocals; + // The explicitly named labels of each function, as (label index, name), + // gathered while writing the code section and used to write the name + // section afterwards. + std::unordered_map>> funcLabelNames; + // Indexes in the string literal section of each StringConst in the wasm. std::unordered_map stringIndexes; diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 7c1cf6b63d1..66b6c6d912b 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -426,8 +426,20 @@ class IRBuilder : public UnifiedExpressionVisitor> { // `setScopeNameHint`. Name nameHint; + // For Try scopes with a label in the text format, the fresh version of that + // label, reserved for whichever of `label` and `branchLabel` is needed + // first. Most tries are only targeted by branches, and giving the name to + // the delegate label up front would leave the branch label with a + // generated name. + Name reservedLabel; + bool labelUsed = false; + // Whether this scope's label was given explicitly (in the text format or in + // the binary name section) rather than generated by us. Recorded in the + // function's `explicitLabelNames`. + bool labelExplicit = false; + // If the control flow scope has an input type, we need to lower it using a // scratch local because we cannot represent control flow input in the IR. Type inputType; @@ -675,6 +687,14 @@ class IRBuilder : public UnifiedExpressionVisitor> { // its stack. std::unordered_map> labelDepths; + // Note that a label was given to us rather than generated by us, so that we + // know it is worth writing out to the name section. + void noteExplicitLabel(Name label) { + if (func && label) { + func->explicitLabelNames.insert(label); + } + } + Name makeFresh(Name label, Index hint = 0) { return Names::getValidName( label, @@ -690,10 +710,16 @@ class IRBuilder : public UnifiedExpressionVisitor> { Result<> pushScope(ScopeCtx&& scope) { if (auto label = scope.getOriginalLabel()) { - // Assign a fresh label to the scope, if necessary. - if (!scope.label) { + // Assign a fresh label to the scope, if necessary. The labels of a try + // are only assigned when they are used, and catches keep the labels of + // their try. + if (scope.getTry()) { + scope.reservedLabel = makeFresh(label); + scope.nameHint = label; + } else if (!scope.label && !scope.getCatch() && !scope.getCatchAll()) { scope.label = makeFresh(label); } + scope.labelExplicit = true; // Record the original label to handle references to it correctly. labelDepths[label].push_back(scopeStack.size() + 1); } diff --git a/src/wasm-stack.h b/src/wasm-stack.h index fede0bf4ccf..90149c65250 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -127,9 +127,21 @@ class BinaryInstWriter : public OverriddenVisitor { void emitUnreachableLocalSet(Index index); void mapLocalsAndEmitHeader(); + // Note the start of a scope: every block, loop, if, try and try_table takes + // an index in the function's label index space, in the order they appear in + // the function body, whether or not they have a name. Records the explicitly + // named ones for the name section. + void noteScopeStart(Name name = Name()); + MappedLocals mappedLocals; + // The explicitly named labels of this function, as (label index, name). + std::vector> labelNames; + private: + // The index the next scope in this function will take. + Index nextLabelIndex = 0; + void emitMemoryAccess(size_t alignment, size_t bytes, uint64_t offset, @@ -565,6 +577,9 @@ class BinaryenIRToBinaryWriter } MappedLocals& getMappedLocals() { return writer.mappedLocals; } + std::vector>& getLabelNames() { + return writer.labelNames; + } private: WasmBinaryWriter& parent; @@ -607,6 +622,9 @@ class StackIRToBinaryWriter { void write(); MappedLocals& getMappedLocals() { return writer.mappedLocals; } + std::vector>& getLabelNames() { + return writer.labelNames; + } private: WasmBinaryWriter& parent; diff --git a/src/wasm.h b/src/wasm.h index 3007b07f7f4..33fcf31e2b9 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "ir/import-names.h" @@ -2448,6 +2449,15 @@ class Function : public Importable { std::unordered_map localNames; std::unordered_map localIndices; + // The label names in this function that were given explicitly - in the text + // format, in the binary name section, or through the C API - as opposed to + // the ones we generated ourselves. Only these are worth writing out to the + // name section. Label names are unique inside a function, so this keeps + // identifying the right labels even as optimizations replace the expressions + // that carry them. A name in here may no longer exist in the body, which is + // harmless. + std::unordered_set explicitLabelNames; + // Source maps debugging info: map expression nodes to their file, line, col, // symbol name. struct DebugLocation { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ad8fce91f52..b096c7db34e 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -512,6 +512,13 @@ void WasmBinaryWriter::writeExpression(Expression* curr) { BinaryenIRToBinaryWriter(*this, o).visit(curr); } +void WasmBinaryWriter::noteLabelNames( + Function* func, std::vector>& labelNames) { + if (!labelNames.empty()) { + funcLabelNames[func->name] = std::move(labelNames); + } +} + void WasmBinaryWriter::writeFunctions() { if (importInfo->getNumDefinedFunctions() == 0) { return; @@ -542,12 +549,14 @@ void WasmBinaryWriter::writeFunctions() { writer.write(); if (debugInfo) { funcMappedLocals[func->name] = std::move(writer.getMappedLocals()); + noteLabelNames(func, writer.getLabelNames()); } } else { BinaryenIRToBinaryWriter writer(*this, o, func, sourceMap, DWARF); writer.write(); if (debugInfo) { funcMappedLocals[func->name] = std::move(writer.getMappedLocals()); + noteLabelNames(func, writer.getLabelNames()); } } size_t size = o.size() - start; @@ -1126,6 +1135,38 @@ void WasmBinaryWriter::writeNames() { } } + // label names + { + std::vector> functionsWithLabelNames; + Index checked = 0; + auto check = [&](Function* curr) { + if (funcLabelNames.count(curr->name)) { + functionsWithLabelNames.push_back({checked, curr}); + } + checked++; + }; + ModuleUtils::iterImportedFunctions(*wasm, check); + ModuleUtils::iterDefinedFunctions(*wasm, check); + assert(checked == indexes.functionIndexes.size()); + if (functionsWithLabelNames.size() > 0) { + auto substart = + startSubsection(BinaryConsts::CustomSections::Subsection::NameLabel); + o << U32LEB(functionsWithLabelNames.size()); + for (auto& [index, func] : functionsWithLabelNames) { + // The labels were gathered in the order they were emitted, which is the + // order of the label index space. + auto& labels = funcLabelNames[func->name]; + o << U32LEB(index); + o << U32LEB(labels.size()); + for (auto& [labelIndex, name] : labels) { + o << U32LEB(labelIndex); + writeInlineString(name.view()); + } + } + finishSubsection(substart); + } + } + // type names { std::vector namedTypes; diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 30bec274fcf..3e0556c7e2c 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -55,6 +55,7 @@ // (`handleBlockNestedPops`). #include +#include #include "ir/child-typer.h" #include "ir/eh-utils.h" @@ -1159,6 +1160,9 @@ Result<> IRBuilder::visitEnd() { if (!label) { return curr; } + if (scope.labelExplicit) { + noteExplicitLabel(label); + } auto* fixed = fixExtraOutput(scope, label, curr); // We can reuse unnamed blocks instead of wrapping them. if (auto* block = fixed->dynCast(); block && !block->name) { @@ -1197,12 +1201,18 @@ Result<> IRBuilder::visitEnd() { block->name = Name(); block = fixExtraOutput(scope, label, block)->cast(); block->name = label; + if (scope.labelExplicit) { + noteExplicitLabel(label); + } block->finalize(block->type, scope.labelUsed ? Block::HasBreak : Block::NoBreak); push(block); } else if (auto* loop = scope.getLoop()) { loop->body = fixExtraOutput(scope, label, *expr); loop->name = scope.label; + if (scope.labelExplicit) { + noteExplicitLabel(scope.label); + } if (scope.inputType != Type::none && scope.labelUsed) { // Branches to this loop carry values, but Binaryen IR does not support // that. Fix this by trampolining the branches through new code that sets @@ -1230,6 +1240,9 @@ Result<> IRBuilder::visitEnd() { } else if (auto* tryy = scope.getTry()) { tryy->body = *expr; tryy->name = scope.label; + if (scope.labelExplicit) { + noteExplicitLabel(scope.label); + } tryy->finalize(tryy->type); push(maybeWrapForLabel(tryy)); } else if (Try* tryy; @@ -1237,6 +1250,9 @@ Result<> IRBuilder::visitEnd() { auto index = scope.getIndex(); setCatchBody(tryy, *expr, index); tryy->name = scope.label; + if (scope.labelExplicit) { + noteExplicitLabel(scope.label); + } tryy->finalize(tryy->type); push(maybeWrapForLabel(tryy)); } else if (auto* trytable = scope.getTryTable()) { @@ -1446,9 +1462,12 @@ Result IRBuilder::getLabelName(Index label, bool forDelegate) { if (!scopeLabel) { // The scope does not already have a name, so we need to create one. Use the - // name from the name section, if we have one. - if (auto hint = (*scope)->nameHint) { + // reserved name or the name from the name section, if we have one. + if (auto reserved = std::exchange((*scope)->reservedLabel, Name())) { + scopeLabel = reserved; + } else if (auto hint = (*scope)->nameHint) { scopeLabel = makeFresh(hint); + (*scope)->labelExplicit = true; } else if ((*scope)->getBlock()) { scopeLabel = makeFresh("block", blockHint++); } else { diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index 4f6c5d6d4e1..c5c7aa19ca3 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -32,13 +32,24 @@ void BinaryInstWriter::emitResultType(Type type) { } } +void BinaryInstWriter::noteScopeStart(Name name) { + auto index = nextLabelIndex++; + if (name && func && parent.getDebugInfo() && + func->explicitLabelNames.count(name)) { + labelNames.push_back({index, name}); + } +} + void BinaryInstWriter::visitBlock(Block* curr) { + noteScopeStart(curr->name); breakStack.push_back(curr->name); o << static_cast(BinaryConsts::Block); emitResultType(curr->type); } void BinaryInstWriter::visitIf(If* curr) { + // An `if` never has a name in Binaryen IR, but it still takes a label index. + noteScopeStart(); // the binary format requires this; we have a block if we need one // TODO: optimize this in Stack IR (if child is a block, we may break to this // instead) @@ -187,6 +198,7 @@ void BinaryInstWriter::emitLoadOpcode(unsigned bytes, bool signed_, Type type) { } void BinaryInstWriter::visitLoop(Loop* curr) { + noteScopeStart(curr->name); breakStack.push_back(curr->name); o << static_cast(BinaryConsts::Loop); emitResultType(curr->type); @@ -2409,12 +2421,16 @@ void BinaryInstWriter::visitElemDrop(ElemDrop* curr) { } void BinaryInstWriter::visitTry(Try* curr) { + noteScopeStart(curr->name); breakStack.push_back(curr->name); o << static_cast(BinaryConsts::Try); emitResultType(curr->type); } void BinaryInstWriter::visitTryTable(TryTable* curr) { + // A `try_table` never has a name in Binaryen IR, but it still takes a label + // index. + noteScopeStart(); o << static_cast(BinaryConsts::TryTable); emitResultType(curr->type); o << U32LEB(curr->catchTags.size()); diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 9be1b56cc5d..e28c0fd052c 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -1760,7 +1760,10 @@ Type Function::getLocalType(Index index) { } } -void Function::clearNames() { localNames.clear(); } +void Function::clearNames() { + localNames.clear(); + explicitLabelNames.clear(); +} void Function::clearDebugInfo() { localIndices.clear(); diff --git a/test/example/c-api-unused-mem.txt b/test/example/c-api-unused-mem.txt index 48ea5982f47..11c69e0c390 100644 --- a/test/example/c-api-unused-mem.txt +++ b/test/example/c-api-unused-mem.txt @@ -36,7 +36,7 @@ (call $main) ) ) -133 +153 (module (type $0 (func)) (memory $0 1024 1024) @@ -47,13 +47,13 @@ (local $0 i32) (local $1 i32) (local $2 i64) - (block $block + (block $block$2$break (local.set $0 (i32.load (i32.const 0) ) ) - (br $block) + (br $block$2$break) ) (i32.store (i32.const 0) diff --git a/test/lit/basic/custom-descriptors.wast b/test/lit/basic/custom-descriptors.wast index c9eb8cd01e5..62094e4e3fc 100644 --- a/test/lit/basic/custom-descriptors.wast +++ b/test/lit/basic/custom-descriptors.wast @@ -118,14 +118,14 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $ref-get-desc (type $16) (param $described (ref null $described)) (param $middle-exact (ref null (exact $middle))) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref $middle)) + ;; CHECK-BIN-NEXT: (block $l1 (result (ref $middle)) ;; CHECK-BIN-NEXT: (ref.get_desc $described ;; CHECK-BIN-NEXT: (local.get $described) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref (exact $describing))) + ;; CHECK-BIN-NEXT: (block $l2 (result (ref (exact $describing))) ;; CHECK-BIN-NEXT: (ref.get_desc $middle ;; CHECK-BIN-NEXT: (local.get $middle-exact) ;; CHECK-BIN-NEXT: ) @@ -190,9 +190,9 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq (type $7) (param $any anyref) (param $descriptor (ref null $describing)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result (ref null $middle)) + ;; CHECK-BIN-NEXT: (block $l (result (ref null $middle)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (br_on_cast_desc_eq $block anyref (ref null $middle) + ;; CHECK-BIN-NEXT: (br_on_cast_desc_eq $l anyref (ref null $middle) ;; CHECK-BIN-NEXT: (local.get $any) ;; CHECK-BIN-NEXT: (local.get $descriptor) ;; CHECK-BIN-NEXT: ) @@ -225,8 +225,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq-fail (type $7) (param $any anyref) (param $descriptor (ref null $describing)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result anyref) - ;; CHECK-BIN-NEXT: (br_on_cast_desc_eq_fail $block anyref (ref null $middle) + ;; CHECK-BIN-NEXT: (block $l (result anyref) + ;; CHECK-BIN-NEXT: (br_on_cast_desc_eq_fail $l anyref (ref null $middle) ;; CHECK-BIN-NEXT: (local.get $any) ;; CHECK-BIN-NEXT: (local.get $descriptor) ;; CHECK-BIN-NEXT: ) @@ -262,7 +262,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq-unreachable (type $6) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref null $middle)) + ;; CHECK-BIN-NEXT: (block $l (result (ref null $middle)) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -296,7 +296,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq-fail-unreachable (type $6) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref null $middle)) + ;; CHECK-BIN-NEXT: (block $l (result (ref null $middle)) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -325,7 +325,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq-unreachable-desc (type $8) (param $descriptor (ref null $describing)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref null $middle)) + ;; CHECK-BIN-NEXT: (block $l (result (ref null $middle)) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -355,7 +355,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br-on-cast-desc-eq-fail-unreachable-desc (type $8) (param $descriptor (ref null $describing)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block (result (ref null $middle)) + ;; CHECK-BIN-NEXT: (block $l (result (ref null $middle)) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/exception-handling-legacy.wast b/test/lit/basic/exception-handling-legacy.wast index 151e74a1ce3..96f6b0eeeea 100644 --- a/test/lit/basic/exception-handling-legacy.wast +++ b/test/lit/basic/exception-handling-legacy.wast @@ -180,31 +180,31 @@ ) ;; CHECK-TEXT: (func $try-with-block-label (type $0) - ;; CHECK-TEXT-NEXT: (block $label - ;; CHECK-TEXT-NEXT: (try $l1 + ;; CHECK-TEXT-NEXT: (block $l1 + ;; CHECK-TEXT-NEXT: (try ;; CHECK-TEXT-NEXT: (do - ;; CHECK-TEXT-NEXT: (br $label) + ;; CHECK-TEXT-NEXT: (br $l1) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: (catch $e-i32 ;; CHECK-TEXT-NEXT: (drop ;; CHECK-TEXT-NEXT: (pop i32) ;; CHECK-TEXT-NEXT: ) - ;; CHECK-TEXT-NEXT: (br $label) + ;; CHECK-TEXT-NEXT: (br $l1) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $try-with-block-label (type $0) - ;; CHECK-BIN-NEXT: (block $block + ;; CHECK-BIN-NEXT: (block $l1 ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $l1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch $e-i32 ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (pop i32) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $l1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) @@ -604,19 +604,19 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $inner-delegate-target-outer-catch (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all @@ -644,24 +644,24 @@ ) ;; CHECK-TEXT: (func $branch-and-delegate-target-same-try-label (type $0) - ;; CHECK-TEXT-NEXT: (block $label - ;; CHECK-TEXT-NEXT: (try $l0 + ;; CHECK-TEXT-NEXT: (block $l0 + ;; CHECK-TEXT-NEXT: (try $l00 ;; CHECK-TEXT-NEXT: (do ;; CHECK-TEXT-NEXT: (try ;; CHECK-TEXT-NEXT: (do - ;; CHECK-TEXT-NEXT: (br_if $label + ;; CHECK-TEXT-NEXT: (br_if $l0 ;; CHECK-TEXT-NEXT: (i32.const 1) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) - ;; CHECK-TEXT-NEXT: (delegate $l0) + ;; CHECK-TEXT-NEXT: (delegate $l00) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: (try ;; CHECK-TEXT-NEXT: (do - ;; CHECK-TEXT-NEXT: (br_if $label + ;; CHECK-TEXT-NEXT: (br_if $l0 ;; CHECK-TEXT-NEXT: (i32.const 1) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) - ;; CHECK-TEXT-NEXT: (delegate $l0) + ;; CHECK-TEXT-NEXT: (delegate $l00) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: (catch_all @@ -670,24 +670,24 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $branch-and-delegate-target-same-try-label (type $0) - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (block $l0 + ;; CHECK-BIN-NEXT: (try $l00 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do - ;; CHECK-BIN-NEXT: (br_if $block + ;; CHECK-BIN-NEXT: (br_if $l0 ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $l00) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do - ;; CHECK-BIN-NEXT: (br_if $block + ;; CHECK-BIN-NEXT: (br_if $l0 ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $l00) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all @@ -734,13 +734,13 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $inner-delegate-target-outer-delegate (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (delegate 0) @@ -803,7 +803,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $try-catch-rethrow (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) @@ -811,10 +811,10 @@ ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (pop i32) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -835,7 +835,7 @@ ) ;; CHECK-TEXT: (func $branch-and-rethrow-target-same-try-label (type $0) - ;; CHECK-TEXT-NEXT: (block $label + ;; CHECK-TEXT-NEXT: (block $l00 ;; CHECK-TEXT-NEXT: (try $l0 ;; CHECK-TEXT-NEXT: (do ;; CHECK-TEXT-NEXT: (call $foo) @@ -847,14 +847,14 @@ ;; CHECK-TEXT-NEXT: (rethrow $l0) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: (catch_all - ;; CHECK-TEXT-NEXT: (br $label) + ;; CHECK-TEXT-NEXT: (br $l00) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $branch-and-rethrow-target-same-try-label (type $0) - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (block $l00 + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) @@ -862,10 +862,10 @@ ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (pop i32) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $l00) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -914,7 +914,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $nested-rethrow (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) @@ -927,10 +927,10 @@ ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (pop i32) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -987,7 +987,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $rnested-rethrow-with-interleaving-block (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) @@ -1000,13 +1000,13 @@ ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (pop i32) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (block $b0 + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -1070,28 +1070,28 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $rethrow-within-nested-try-part (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $l0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do - ;; CHECK-BIN-NEXT: (rethrow $label) + ;; CHECK-BIN-NEXT: (rethrow $l0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (try $label1 + ;; CHECK-BIN-NEXT: (try $l00 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do - ;; CHECK-BIN-NEXT: (rethrow $label1) + ;; CHECK-BIN-NEXT: (rethrow $l00) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (catch_all ;; CHECK-BIN-NEXT: ) @@ -1235,7 +1235,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $catchless-try-with-inner-delegate (type $0) - ;; CHECK-BIN-NEXT: (try $label + ;; CHECK-BIN-NEXT: (try $label$0 ;; CHECK-BIN-NEXT: (do ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do @@ -1243,7 +1243,7 @@ ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (delegate $label) + ;; CHECK-BIN-NEXT: (delegate $label$0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) @@ -1278,8 +1278,8 @@ ;; CHECK-TEXT-NEXT: (nop) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $nested-delegate-within-block (type $0) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (block + ;; CHECK-BIN-NEXT: (block $l0 + ;; CHECK-BIN-NEXT: (block $l1 ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (try ;; CHECK-BIN-NEXT: (do diff --git a/test/lit/basic/exception-handling-no-gc.wast b/test/lit/basic/exception-handling-no-gc.wast index 611853a9398..44fa546a505 100644 --- a/test/lit/basic/exception-handling-no-gc.wast +++ b/test/lit/basic/exception-handling-no-gc.wast @@ -7,8 +7,8 @@ (module ;; CHECK: (func $test (result exnref) - ;; CHECK-NEXT: (block $block (result exnref) - ;; CHECK-NEXT: (try_table (catch_all_ref $block) + ;; CHECK-NEXT: (block $label (result exnref) + ;; CHECK-NEXT: (try_table (catch_all_ref $label) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) diff --git a/test/lit/basic/exception-handling.wast b/test/lit/basic/exception-handling.wast index 0a0dd3e8904..7b47716f66e 100644 --- a/test/lit/basic/exception-handling.wast +++ b/test/lit/basic/exception-handling.wast @@ -166,8 +166,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $simple-try-table-and-throw (type $2) (result i32) - ;; CHECK-BIN-NEXT: (block $block (result i32) - ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $block) + ;; CHECK-BIN-NEXT: (block $l-catch (result i32) + ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $l-catch) ;; CHECK-BIN-NEXT: (throw $e-i32 ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) @@ -196,8 +196,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $try-table-and-throw-ref (type $0) ;; CHECK-BIN-NEXT: (throw_ref - ;; CHECK-BIN-NEXT: (block $block (result exnref) - ;; CHECK-BIN-NEXT: (try_table (catch_all_ref $block) + ;; CHECK-BIN-NEXT: (block $l-catch-all-ref (result exnref) + ;; CHECK-BIN-NEXT: (try_table (catch_all_ref $l-catch-all-ref) ;; CHECK-BIN-NEXT: (throw $e-i64 ;; CHECK-BIN-NEXT: (i64.const 0) ;; CHECK-BIN-NEXT: ) @@ -241,20 +241,20 @@ ;; CHECK-BIN-NEXT: (local $scratch_2 (tuple i32 i64 exnref)) ;; CHECK-BIN-NEXT: (local $scratch_3 i64) ;; CHECK-BIN-NEXT: (local $scratch_4 i32) - ;; CHECK-BIN-NEXT: (block $block2 + ;; CHECK-BIN-NEXT: (block $outer ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (block (result i32) ;; CHECK-BIN-NEXT: (local.set $scratch_4 ;; CHECK-BIN-NEXT: (tuple.extract 3 0 ;; CHECK-BIN-NEXT: (local.tee $scratch_2 - ;; CHECK-BIN-NEXT: (block $block1 (type $4) (result i32 i64 exnref) + ;; CHECK-BIN-NEXT: (block $l-catch-ref (type $4) (result i32 i64 exnref) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (block (result i32) ;; CHECK-BIN-NEXT: (local.set $scratch_1 ;; CHECK-BIN-NEXT: (tuple.extract 2 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block $block (type $3) (result i32 i64) - ;; CHECK-BIN-NEXT: (try_table (catch $e-i32-i64 $block) (catch_ref $e-i32-i64 $block1) + ;; CHECK-BIN-NEXT: (block $l-catch (type $3) (result i32 i64) + ;; CHECK-BIN-NEXT: (try_table (catch $e-i32-i64 $l-catch) (catch_ref $e-i32-i64 $l-catch-ref) ;; CHECK-BIN-NEXT: (throw $e-i32-i64 ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: (i64.const 0) @@ -273,7 +273,7 @@ ;; CHECK-BIN-NEXT: (local.get $scratch_1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block2) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -340,25 +340,25 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $try-table-all-catch-clauses-empty-tag (type $0) - ;; CHECK-BIN-NEXT: (block $block4 - ;; CHECK-BIN-NEXT: (block $block + ;; CHECK-BIN-NEXT: (block $outer + ;; CHECK-BIN-NEXT: (block $l-catch ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block1 (result exnref) - ;; CHECK-BIN-NEXT: (block $block2 + ;; CHECK-BIN-NEXT: (block $l-catch-ref (result exnref) + ;; CHECK-BIN-NEXT: (block $l-catch-all ;; CHECK-BIN-NEXT: (throw_ref - ;; CHECK-BIN-NEXT: (block $block3 (result exnref) - ;; CHECK-BIN-NEXT: (try_table (catch $e-empty $block) (catch_ref $e-empty $block1) (catch_all $block2) (catch_all_ref $block3) + ;; CHECK-BIN-NEXT: (block $l-catch-all-ref (result exnref) + ;; CHECK-BIN-NEXT: (try_table (catch $e-empty $l-catch) (catch_ref $e-empty $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -419,27 +419,27 @@ ;; CHECK-BIN: (func $try-table-all-catch-clauses-i32-tag (type $0) ;; CHECK-BIN-NEXT: (local $scratch (tuple i32 exnref)) ;; CHECK-BIN-NEXT: (local $scratch_1 i32) - ;; CHECK-BIN-NEXT: (block $block4 + ;; CHECK-BIN-NEXT: (block $outer ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result i32) + ;; CHECK-BIN-NEXT: (block $l-catch (result i32) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (block (result i32) ;; CHECK-BIN-NEXT: (local.set $scratch_1 ;; CHECK-BIN-NEXT: (tuple.extract 2 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block $block1 (type $9) (result i32 exnref) - ;; CHECK-BIN-NEXT: (block $block2 + ;; CHECK-BIN-NEXT: (block $l-catch-ref (type $9) (result i32 exnref) + ;; CHECK-BIN-NEXT: (block $l-catch-all ;; CHECK-BIN-NEXT: (throw_ref - ;; CHECK-BIN-NEXT: (block $block3 (result exnref) - ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $block) (catch_ref $e-i32 $block1) (catch_all $block2) (catch_all_ref $block3) + ;; CHECK-BIN-NEXT: (block $l-catch-all-ref (result exnref) + ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $l-catch) (catch_ref $e-i32 $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -452,7 +452,7 @@ ;; CHECK-BIN-NEXT: (local.get $scratch_1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -519,31 +519,31 @@ ;; CHECK-BIN-NEXT: (local $scratch_2 i32) ;; CHECK-BIN-NEXT: (local $scratch_3 (tuple i32 i64)) ;; CHECK-BIN-NEXT: (local $scratch_4 i32) - ;; CHECK-BIN-NEXT: (block $block4 + ;; CHECK-BIN-NEXT: (block $outer ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (block (result i32) ;; CHECK-BIN-NEXT: (local.set $scratch_4 ;; CHECK-BIN-NEXT: (tuple.extract 2 0 ;; CHECK-BIN-NEXT: (local.tee $scratch_3 - ;; CHECK-BIN-NEXT: (block $block (type $3) (result i32 i64) + ;; CHECK-BIN-NEXT: (block $l-catch (type $3) (result i32 i64) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (block (result i32) ;; CHECK-BIN-NEXT: (local.set $scratch_2 ;; CHECK-BIN-NEXT: (tuple.extract 3 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block $block1 (type $4) (result i32 i64 exnref) - ;; CHECK-BIN-NEXT: (block $block2 + ;; CHECK-BIN-NEXT: (block $l-catch-ref (type $4) (result i32 i64 exnref) + ;; CHECK-BIN-NEXT: (block $l-catch-all ;; CHECK-BIN-NEXT: (throw_ref - ;; CHECK-BIN-NEXT: (block $block3 (result exnref) - ;; CHECK-BIN-NEXT: (try_table (catch $e-i32-i64 $block) (catch_ref $e-i32-i64 $block1) (catch_all $block2) (catch_all_ref $block3) + ;; CHECK-BIN-NEXT: (block $l-catch-all-ref (result exnref) + ;; CHECK-BIN-NEXT: (try_table (catch $e-i32-i64 $l-catch) (catch_ref $e-i32-i64 $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: (call $foo) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -566,7 +566,7 @@ ;; CHECK-BIN-NEXT: (local.get $scratch_2) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block4) + ;; CHECK-BIN-NEXT: (br $outer) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -624,10 +624,10 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $try-table-with-label-and-br (type $2) (result i32) - ;; CHECK-BIN-NEXT: (block $block (result i32) - ;; CHECK-BIN-NEXT: (block $block1 (result i32) - ;; CHECK-BIN-NEXT: (try_table (result i32) (catch $e-i32 $block) - ;; CHECK-BIN-NEXT: (br $block1 + ;; CHECK-BIN-NEXT: (block $l-catch (result i32) + ;; CHECK-BIN-NEXT: (block $l (result i32) + ;; CHECK-BIN-NEXT: (try_table (result i32) (catch $e-i32 $l-catch) + ;; CHECK-BIN-NEXT: (br $l ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -669,11 +669,11 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $nested-try-table (type $1) (result exnref) - ;; CHECK-BIN-NEXT: (block $block (result exnref) + ;; CHECK-BIN-NEXT: (block $l-catch-outer (result exnref) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block1 (result i32) - ;; CHECK-BIN-NEXT: (try_table (catch_all_ref $block) - ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $block1) + ;; CHECK-BIN-NEXT: (block $l-catch-inner (result i32) + ;; CHECK-BIN-NEXT: (try_table (catch_all_ref $l-catch-outer) + ;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $l-catch-inner) ;; CHECK-BIN-NEXT: (if ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: (then diff --git a/test/lit/basic/fn_prolog_epilog.debugInfo.wast b/test/lit/basic/fn_prolog_epilog.debugInfo.wast index 511ea9ce8aa..455855e2431 100644 --- a/test/lit/basic/fn_prolog_epilog.debugInfo.wast +++ b/test/lit/basic/fn_prolog_epilog.debugInfo.wast @@ -45,9 +45,9 @@ ;; CHECK-BIN: (func $0 (type $0) ;; CHECK-BIN-NEXT: (nop) -;; CHECK-BIN-NEXT: (block -;; CHECK-BIN-NEXT: (block $block -;; CHECK-BIN-NEXT: (br $block) +;; CHECK-BIN-NEXT: (block $l0 +;; CHECK-BIN-NEXT: (block $l1 +;; CHECK-BIN-NEXT: (br $l1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (return) diff --git a/test/lit/basic/min.wast b/test/lit/basic/min.wast index e4de0018546..3a8b9ea9c31 100644 --- a/test/lit/basic/min.wast +++ b/test/lit/basic/min.wast @@ -76,7 +76,7 @@ ;; CHECK-BIN-NEXT: (local $n f32) ;; CHECK-BIN-NEXT: (local.tee $n ;; CHECK-BIN-NEXT: (f32.neg - ;; CHECK-BIN-NEXT: (block (result f32) + ;; CHECK-BIN-NEXT: (block $block0 (result f32) ;; CHECK-BIN-NEXT: (i32.store ;; CHECK-BIN-NEXT: (local.get $k) ;; CHECK-BIN-NEXT: (local.get $p) @@ -127,21 +127,21 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $littleswitch (type $2) (param $x i32) (result i32) - ;; CHECK-BIN-NEXT: (block $block2 (result i32) - ;; CHECK-BIN-NEXT: (block $block1 - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (br_table $block $block1 $block + ;; CHECK-BIN-NEXT: (block $topmost (result i32) + ;; CHECK-BIN-NEXT: (block $switch-case$2 + ;; CHECK-BIN-NEXT: (block $switch-case$1 + ;; CHECK-BIN-NEXT: (br_table $switch-case$1 $switch-case$2 $switch-case$1 ;; CHECK-BIN-NEXT: (i32.sub ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block2 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block2 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 2) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/polymorphic_stack.wast b/test/lit/basic/polymorphic_stack.wast index 72a3bceb454..4105f80020b 100644 --- a/test/lit/basic/polymorphic_stack.wast +++ b/test/lit/basic/polymorphic_stack.wast @@ -47,7 +47,9 @@ ;; CHECK-BIN: (import "env" "table" (table $timport$0 9 9 funcref)) ;; CHECK-BIN: (func $break-and-binary (type $0) (result i32) - ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: (block $x (result i32) + ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) (func $break-and-binary (result i32) (block $x (result i32) @@ -225,10 +227,12 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $untaken-break-should-have-value (type $0) (result i32) - ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (i32.const 0) + ;; CHECK-BIN-NEXT: (block $x (result i32) + ;; CHECK-BIN-NEXT: (drop + ;; CHECK-BIN-NEXT: (i32.const 0) + ;; CHECK-BIN-NEXT: ) + ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) (func $untaken-break-should-have-value (result i32) (block $x (result i32) @@ -268,7 +272,7 @@ ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block (result i32) + ;; CHECK-BIN-NEXT: (block $label$0 (result i32) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) @@ -307,8 +311,10 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $br_table_unreachable_to_also_unreachable (type $0) (result i32) - ;; CHECK-BIN-NEXT: (block (result i32) - ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: (block $a (result i32) + ;; CHECK-BIN-NEXT: (block $b (result i32) + ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) (func $br_table_unreachable_to_also_unreachable (result i32) @@ -343,19 +349,21 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $untaken-br_if (type $0) (result i32) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (if - ;; CHECK-BIN-NEXT: (i32.const 0) - ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (unreachable) - ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (else - ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: (block $label$8 (result i32) + ;; CHECK-BIN-NEXT: (block $label$9 + ;; CHECK-BIN-NEXT: (if + ;; CHECK-BIN-NEXT: (i32.const 0) + ;; CHECK-BIN-NEXT: (then + ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: ) + ;; CHECK-BIN-NEXT: (else + ;; CHECK-BIN-NEXT: (unreachable) + ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) + ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) (func $untaken-br_if (result i32) (block $label$8 (result i32) diff --git a/test/lit/basic/reference-types.wast b/test/lit/basic/reference-types.wast index 4058d316d6f..608c5673c30 100644 --- a/test/lit/basic/reference-types.wast +++ b/test/lit/basic/reference-types.wast @@ -1237,11 +1237,11 @@ ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block13 (result eqref) + ;; CHECK-BIN-NEXT: (block $tryend (result eqref) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block12 (result i32) - ;; CHECK-BIN-NEXT: (br $block13 - ;; CHECK-BIN-NEXT: (try_table (result eqref) (catch $e-i32 $block12) + ;; CHECK-BIN-NEXT: (block $catch (result i32) + ;; CHECK-BIN-NEXT: (br $tryend + ;; CHECK-BIN-NEXT: (try_table (result eqref) (catch $e-i32 $catch) ;; CHECK-BIN-NEXT: (local.get $local_eqref) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -1251,11 +1251,11 @@ ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block15 (result funcref) + ;; CHECK-BIN-NEXT: (block $tryend0 (result funcref) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block14 (result i32) - ;; CHECK-BIN-NEXT: (br $block15 - ;; CHECK-BIN-NEXT: (try_table (result funcref) (catch $e-i32 $block14) + ;; CHECK-BIN-NEXT: (block $catch0 (result i32) + ;; CHECK-BIN-NEXT: (br $tryend0 + ;; CHECK-BIN-NEXT: (try_table (result funcref) (catch $e-i32 $catch0) ;; CHECK-BIN-NEXT: (ref.func $foo) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -1265,11 +1265,11 @@ ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block17 (result anyref) + ;; CHECK-BIN-NEXT: (block $tryend1 (result anyref) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block16 (result i32) - ;; CHECK-BIN-NEXT: (br $block17 - ;; CHECK-BIN-NEXT: (try_table (result anyref) (catch $e-i32 $block16) + ;; CHECK-BIN-NEXT: (block $catch1 (result i32) + ;; CHECK-BIN-NEXT: (br $tryend1 + ;; CHECK-BIN-NEXT: (try_table (result anyref) (catch $e-i32 $catch1) ;; CHECK-BIN-NEXT: (local.get $local_eqref) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -1279,11 +1279,11 @@ ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block19 (result anyref) + ;; CHECK-BIN-NEXT: (block $tryend2 (result anyref) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block18 (result i32) - ;; CHECK-BIN-NEXT: (br $block19 - ;; CHECK-BIN-NEXT: (try_table (result anyref) (catch $e-i32 $block18) + ;; CHECK-BIN-NEXT: (block $catch2 (result i32) + ;; CHECK-BIN-NEXT: (br $tryend2 + ;; CHECK-BIN-NEXT: (try_table (result anyref) (catch $e-i32 $catch2) ;; CHECK-BIN-NEXT: (ref.null none) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/reg_switch.wast b/test/lit/basic/reg_switch.wast index a1d00e8aa1c..841ff9c25f7 100644 --- a/test/lit/basic/reg_switch.wast +++ b/test/lit/basic/reg_switch.wast @@ -35,8 +35,8 @@ ;; CHECK-BIN-NEXT: (if ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (br_table $block + ;; CHECK-BIN-NEXT: (block $A + ;; CHECK-BIN-NEXT: (br_table $A ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/stack_switching.wast b/test/lit/basic/stack_switching.wast index 541c200ecec..5978a4fe1ca 100644 --- a/test/lit/basic/stack_switching.wast +++ b/test/lit/basic/stack_switching.wast @@ -297,8 +297,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $unhandled-3 (type $f1) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e2 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e2 $h) ;; CHECK-BIN-NEXT: (cont.new $k1 ;; CHECK-BIN-NEXT: (ref.func $f1) ;; CHECK-BIN-NEXT: ) @@ -329,8 +329,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $handled (type $f1) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h) ;; CHECK-BIN-NEXT: (cont.new $k1 ;; CHECK-BIN-NEXT: (ref.func $f1) ;; CHECK-BIN-NEXT: ) @@ -372,8 +372,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $uncaught-1 (type $f1) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h) ;; CHECK-BIN-NEXT: (cont.new $k1 ;; CHECK-BIN-NEXT: (ref.func $f2) ;; CHECK-BIN-NEXT: ) @@ -404,8 +404,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $uncaught-2 (type $f1) ;; CHECK-BIN-NEXT: (resume_throw $k1 $exn - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h) ;; CHECK-BIN-NEXT: (cont.new $k1 ;; CHECK-BIN-NEXT: (ref.func $f1) ;; CHECK-BIN-NEXT: ) @@ -456,8 +456,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $uncaught-3 (type $f1) ;; CHECK-BIN-NEXT: (resume_throw $k1 $exn - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h) ;; CHECK-BIN-NEXT: (cont.new $k1 ;; CHECK-BIN-NEXT: (ref.func $f3) ;; CHECK-BIN-NEXT: ) @@ -527,8 +527,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $nl2 (type $2) (param $k (ref $k1)) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h) ;; CHECK-BIN-NEXT: (local.get $k) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) @@ -573,16 +573,16 @@ ;; CHECK-BIN: (func $nl3 (type $2) (param $k (ref $k1)) ;; CHECK-BIN-NEXT: (local $k' (ref null $k1)) ;; CHECK-BIN-NEXT: (local.set $k' - ;; CHECK-BIN-NEXT: (block $block (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block) + ;; CHECK-BIN-NEXT: (block $h1 (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h1) ;; CHECK-BIN-NEXT: (local.get $k) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (block $block1 (result (ref $k1)) - ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $block1) + ;; CHECK-BIN-NEXT: (block $h2 (result (ref $k1)) + ;; CHECK-BIN-NEXT: (resume $k1 (on $e1 $h2) ;; CHECK-BIN-NEXT: (local.get $k') ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) diff --git a/test/lit/basic/stack_switching_resume.wast b/test/lit/basic/stack_switching_resume.wast index 10116ce31f4..bb70db56a06 100644 --- a/test/lit/basic/stack_switching_resume.wast +++ b/test/lit/basic/stack_switching_resume.wast @@ -66,9 +66,9 @@ ;; CHECK-BIN-NEXT: (local.set $scratch_2 ;; CHECK-BIN-NEXT: (tuple.extract 2 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block $block (type $3) (result i32 (ref $ct)) + ;; CHECK-BIN-NEXT: (block $handler (type $3) (result i32 (ref $ct)) ;; CHECK-BIN-NEXT: (return - ;; CHECK-BIN-NEXT: (resume $ct (on $t $block) + ;; CHECK-BIN-NEXT: (resume $ct (on $t $handler) ;; CHECK-BIN-NEXT: (i32.const 123) ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/stack_switching_resume_throw.wast b/test/lit/basic/stack_switching_resume_throw.wast index cc5de8ef406..73057998abf 100644 --- a/test/lit/basic/stack_switching_resume_throw.wast +++ b/test/lit/basic/stack_switching_resume_throw.wast @@ -58,9 +58,9 @@ ;; CHECK-BIN-NEXT: (local.set $scratch_2 ;; CHECK-BIN-NEXT: (tuple.extract 2 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block $block (type $5) (result i32 (ref $ct)) + ;; CHECK-BIN-NEXT: (block $handler (type $5) (result i32 (ref $ct)) ;; CHECK-BIN-NEXT: (return - ;; CHECK-BIN-NEXT: (resume_throw $ct $e (on $t $block) + ;; CHECK-BIN-NEXT: (resume_throw $ct $e (on $t $handler) ;; CHECK-BIN-NEXT: (i64.const 123) ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/types-function-references.wast b/test/lit/basic/types-function-references.wast index dfff790bc18..664f72f0bdc 100644 --- a/test/lit/basic/types-function-references.wast +++ b/test/lit/basic/types-function-references.wast @@ -200,7 +200,7 @@ ;; CHECK-BIN-NEXT: (local.set $scratch_2 ;; CHECK-BIN-NEXT: (tuple.extract 3 0 ;; CHECK-BIN-NEXT: (local.tee $scratch - ;; CHECK-BIN-NEXT: (block (type $10) (result i32 (ref null $mixed_results) f64) + ;; CHECK-BIN-NEXT: (block $block (type $10) (result i32 (ref null $mixed_results) f64) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/unit.wat b/test/lit/basic/unit.wat index 43901e3bc55..7295946e76f 100644 --- a/test/lit/basic/unit.wat +++ b/test/lit/basic/unit.wat @@ -215,7 +215,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $importedDoubles (type $4) (result f64) ;; CHECK-BIN-NEXT: (local $temp f64) - ;; CHECK-BIN-NEXT: (block $block (result f64) + ;; CHECK-BIN-NEXT: (block $topmost (result f64) ;; CHECK-BIN-NEXT: (local.set $temp ;; CHECK-BIN-NEXT: (f64.add ;; CHECK-BIN-NEXT: (f64.add @@ -248,7 +248,7 @@ ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (f64.const -3.4) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -261,7 +261,7 @@ ;; CHECK-BIN-NEXT: (f64.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (f64.const 5.6) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -381,14 +381,14 @@ ;; CHECK-BIN-NEXT: (local $t f64) ;; CHECK-BIN-NEXT: (local $Int f64) ;; CHECK-BIN-NEXT: (local $Double i32) - ;; CHECK-BIN-NEXT: (block $block (result f64) + ;; CHECK-BIN-NEXT: (block $topmost (result f64) ;; CHECK-BIN-NEXT: (if ;; CHECK-BIN-NEXT: (f64.gt ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: (f64.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (f64.const 1.2) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -399,7 +399,7 @@ ;; CHECK-BIN-NEXT: (f64.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (f64.const -3.4) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -410,7 +410,7 @@ ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (f64.const 5.6) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -421,7 +421,7 @@ ;; CHECK-BIN-NEXT: (local.get $y) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (then - ;; CHECK-BIN-NEXT: (br $block + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) @@ -628,13 +628,13 @@ ;; CHECK-BIN-NEXT: (local $J f64) ;; CHECK-BIN-NEXT: (local.set $J ;; CHECK-BIN-NEXT: (f64.sub - ;; CHECK-BIN-NEXT: (block (result f64) + ;; CHECK-BIN-NEXT: (block $block0 (result f64) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (f64.const 0.1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (f64.const 5.1) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block (result f64) + ;; CHECK-BIN-NEXT: (block $block1 (result f64) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (f64.const 3.2) ;; CHECK-BIN-NEXT: ) @@ -749,76 +749,76 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $switcher (type $6) (param $x i32) (result i32) - ;; CHECK-BIN-NEXT: (block $block3 (result i32) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (block $block2 - ;; CHECK-BIN-NEXT: (block $block1 - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (br_table $block $block1 $block2 + ;; CHECK-BIN-NEXT: (block $topmost (result i32) + ;; CHECK-BIN-NEXT: (block $switch$0 + ;; CHECK-BIN-NEXT: (block $switch-default$3 + ;; CHECK-BIN-NEXT: (block $switch-case$2 + ;; CHECK-BIN-NEXT: (block $switch-case$1 + ;; CHECK-BIN-NEXT: (br_table $switch-case$1 $switch-case$2 $switch-default$3 ;; CHECK-BIN-NEXT: (i32.sub ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block3 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block3 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 2) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (nop) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (block $block5 - ;; CHECK-BIN-NEXT: (block $block4 - ;; CHECK-BIN-NEXT: (block $block6 - ;; CHECK-BIN-NEXT: (br_table $block4 $block5 $block5 $block5 $block5 $block5 $block5 $block6 $block5 + ;; CHECK-BIN-NEXT: (block $switch$4 + ;; CHECK-BIN-NEXT: (block $switch-default$7 + ;; CHECK-BIN-NEXT: (block $switch-case$6 + ;; CHECK-BIN-NEXT: (block $switch-case$5 + ;; CHECK-BIN-NEXT: (br_table $switch-case$6 $switch-default$7 $switch-default$7 $switch-default$7 $switch-default$7 $switch-default$7 $switch-default$7 $switch-case$5 $switch-default$7 ;; CHECK-BIN-NEXT: (i32.sub ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: (i32.const 5) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block3 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 121) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block3 + ;; CHECK-BIN-NEXT: (br $topmost ;; CHECK-BIN-NEXT: (i32.const 51) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (nop) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block $block12 - ;; CHECK-BIN-NEXT: (block $block8 - ;; CHECK-BIN-NEXT: (block $block7 - ;; CHECK-BIN-NEXT: (block $block9 - ;; CHECK-BIN-NEXT: (block $block10 - ;; CHECK-BIN-NEXT: (block $block11 - ;; CHECK-BIN-NEXT: (br_table $block7 $block8 $block8 $block9 $block8 $block8 $block8 $block8 $block10 $block8 $block11 $block8 + ;; CHECK-BIN-NEXT: (block $label$break$Lout + ;; CHECK-BIN-NEXT: (block $switch-default$16 + ;; CHECK-BIN-NEXT: (block $switch-case$15 + ;; CHECK-BIN-NEXT: (block $switch-case$12 + ;; CHECK-BIN-NEXT: (block $switch-case$9 + ;; CHECK-BIN-NEXT: (block $switch-case$8 + ;; CHECK-BIN-NEXT: (br_table $switch-case$15 $switch-default$16 $switch-default$16 $switch-case$12 $switch-default$16 $switch-default$16 $switch-default$16 $switch-default$16 $switch-case$9 $switch-default$16 $switch-case$8 $switch-default$16 ;; CHECK-BIN-NEXT: (i32.sub ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: (i32.const 2) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block12) + ;; CHECK-BIN-NEXT: (br $label$break$Lout) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block12) + ;; CHECK-BIN-NEXT: (br $label$break$Lout) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block $block13 - ;; CHECK-BIN-NEXT: (loop - ;; CHECK-BIN-NEXT: (br $block13) + ;; CHECK-BIN-NEXT: (block $while-out$10 + ;; CHECK-BIN-NEXT: (loop $while-in$11 + ;; CHECK-BIN-NEXT: (br $while-out$10) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (block - ;; CHECK-BIN-NEXT: (loop - ;; CHECK-BIN-NEXT: (br $block12) + ;; CHECK-BIN-NEXT: (block $while-out$13 + ;; CHECK-BIN-NEXT: (loop $while-in$14 + ;; CHECK-BIN-NEXT: (br $label$break$Lout) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) @@ -921,8 +921,8 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $blocker (type $FUNCSIG$v) - ;; CHECK-BIN-NEXT: (block $block - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (block $label$break$L + ;; CHECK-BIN-NEXT: (br $label$break$L) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) (func $blocker (type $FUNCSIG$v) @@ -1118,7 +1118,7 @@ ;; CHECK-BIN-NEXT: (local $y f64) ;; CHECK-BIN-NEXT: (local $z f32) ;; CHECK-BIN-NEXT: (local.set $x - ;; CHECK-BIN-NEXT: (block (result i32) + ;; CHECK-BIN-NEXT: (block $block1 (result i32) ;; CHECK-BIN-NEXT: (local.set $asm2wasm_i32_temp ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) @@ -1340,11 +1340,11 @@ ;; CHECK-TEXT-NEXT: (i32.const 0) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $block_and_after (type $5) (result i32) - ;; CHECK-BIN-NEXT: (block $block + ;; CHECK-BIN-NEXT: (block $waka ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (i32.const 1) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $waka) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (i32.const 0) ;; CHECK-BIN-NEXT: ) @@ -1366,7 +1366,7 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $loop-roundtrip (type $7) (param $0 f64) (result f64) - ;; CHECK-BIN-NEXT: (loop (result f64) + ;; CHECK-BIN-NEXT: (loop $loop-in1 (result f64) ;; CHECK-BIN-NEXT: (drop ;; CHECK-BIN-NEXT: (local.get $0) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/unreachable-code.wast b/test/lit/basic/unreachable-code.wast index baf1564960f..1eae708a9de 100644 --- a/test/lit/basic/unreachable-code.wast +++ b/test/lit/basic/unreachable-code.wast @@ -293,9 +293,9 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $recurse (type $0) ;; CHECK-BIN-NEXT: (nop) - ;; CHECK-BIN-NEXT: (block $block + ;; CHECK-BIN-NEXT: (block $b ;; CHECK-BIN-NEXT: (nop) - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $b) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (nop) ;; CHECK-BIN-NEXT: ) @@ -323,11 +323,11 @@ ;; CHECK-TEXT-NEXT: ) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (func $recurse-b (type $0) - ;; CHECK-BIN-NEXT: (block $block + ;; CHECK-BIN-NEXT: (block $a ;; CHECK-BIN-NEXT: (nop) - ;; CHECK-BIN-NEXT: (block + ;; CHECK-BIN-NEXT: (block $b ;; CHECK-BIN-NEXT: (nop) - ;; CHECK-BIN-NEXT: (br $block) + ;; CHECK-BIN-NEXT: (br $a) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/basic/untaken-br_if.wast b/test/lit/basic/untaken-br_if.wast index 4d982654977..28e6048b4a9 100644 --- a/test/lit/basic/untaken-br_if.wast +++ b/test/lit/basic/untaken-br_if.wast @@ -37,10 +37,12 @@ ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: (else - ;; CHECK-BIN-NEXT: (drop - ;; CHECK-BIN-NEXT: (f32.const 1) + ;; CHECK-BIN-NEXT: (block $label$1 (result f32) + ;; CHECK-BIN-NEXT: (drop + ;; CHECK-BIN-NEXT: (f32.const 1) + ;; CHECK-BIN-NEXT: ) + ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) - ;; CHECK-BIN-NEXT: (unreachable) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) ;; CHECK-BIN-NEXT: ) diff --git a/test/lit/binary/label-names-write.wast b/test/lit/binary/label-names-write.wast new file mode 100644 index 00000000000..e973e682ea1 --- /dev/null +++ b/test/lit/binary/label-names-write.wast @@ -0,0 +1,292 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; Test that we write explicit label names to the name section with -g, and +;; that we do not write the names we generate ourselves. + +;; RUN: wasm-as %s -all -g -o %t.wasm +;; RUN: wasm-dis %t.wasm -all -o - | filecheck %s --check-prefix=DEBUG +;; RUN: wasm-as %s -all -o %t.nodebug.wasm +;; RUN: wasm-dis %t.nodebug.wasm -all -o - | filecheck %s --check-prefix=NODEBUG +;; RUN: wasm-opt %s -all -g --inlining -o %t.inline.wasm +;; RUN: wasm-dis %t.inline.wasm -all -o - | filecheck %s --check-prefix=INLINE + +(module + ;; DEBUG: (type $0 (func (param i32) (result i32))) + + ;; DEBUG: (type $1 (func (result i32))) + + ;; DEBUG: (func $f (type $0) (param $p i32) (result i32) + ;; DEBUG-NEXT: (drop + ;; DEBUG-NEXT: (i32.const 0) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (block $named-block (result i32) + ;; DEBUG-NEXT: (loop $named-loop + ;; DEBUG-NEXT: (br_if $named-loop + ;; DEBUG-NEXT: (local.get $p) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (block $block + ;; DEBUG-NEXT: (br_if $block + ;; DEBUG-NEXT: (local.get $p) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (block $unused-block + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (block $used-if + ;; DEBUG-NEXT: (if + ;; DEBUG-NEXT: (local.get $p) + ;; DEBUG-NEXT: (then + ;; DEBUG-NEXT: (br $used-if) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (i32.const 42) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; INLINE: (type $0 (func (param i32) (result i32))) + + ;; INLINE: (type $1 (func (result i32))) + + ;; INLINE: (func $f (type $0) (param $p i32) (result i32) + ;; INLINE-NEXT: (drop + ;; INLINE-NEXT: (i32.const 0) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (block $named-block (result i32) + ;; INLINE-NEXT: (loop $named-loop + ;; INLINE-NEXT: (br_if $named-loop + ;; INLINE-NEXT: (local.get $p) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (block $block + ;; INLINE-NEXT: (br_if $block + ;; INLINE-NEXT: (local.get $p) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (block $unused-block + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (block $used-if + ;; INLINE-NEXT: (if + ;; INLINE-NEXT: (local.get $p) + ;; INLINE-NEXT: (then + ;; INLINE-NEXT: (br $used-if) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (i32.const 42) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + (func $f (param $p i32) (result i32) + (drop (i32.const 0)) + (block $named-block (result i32) + (loop $named-loop + (br_if $named-loop (local.get $p)) + ) + (block ;; unnamed: still takes a label index + (br_if 0 (local.get $p)) + ) + (block $unused-block) + (if $used-if (local.get $p) (then (br $used-if))) + (i32.const 42) + ) + ) + + ;; Branches to a try target a block wrapping it, and delegates target the try + ;; itself. The explicit name goes to whichever is used first, and the other + ;; one gets a name derived from it. + ;; DEBUG: (func $try (type $0) (param $p i32) (result i32) + ;; DEBUG-NEXT: (drop + ;; DEBUG-NEXT: (block $branch-only (result i32) + ;; DEBUG-NEXT: (try (result i32) + ;; DEBUG-NEXT: (do + ;; DEBUG-NEXT: (drop + ;; DEBUG-NEXT: (br_if $branch-only + ;; DEBUG-NEXT: (i32.const 0) + ;; DEBUG-NEXT: (local.get $p) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (i32.const 1) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (catch_all + ;; DEBUG-NEXT: (i32.const 2) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (block $both (result i32) + ;; DEBUG-NEXT: (try $both0 (result i32) + ;; DEBUG-NEXT: (do + ;; DEBUG-NEXT: (drop + ;; DEBUG-NEXT: (br_if $both + ;; DEBUG-NEXT: (i32.const 0) + ;; DEBUG-NEXT: (local.get $p) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (try + ;; DEBUG-NEXT: (do + ;; DEBUG-NEXT: (nop) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (delegate $both0) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (i32.const 1) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: (catch_all + ;; DEBUG-NEXT: (i32.const 2) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; DEBUG-NEXT: ) + ;; INLINE: (func $try (type $0) (param $p i32) (result i32) + ;; INLINE-NEXT: (drop + ;; INLINE-NEXT: (block $branch-only (result i32) + ;; INLINE-NEXT: (try (result i32) + ;; INLINE-NEXT: (do + ;; INLINE-NEXT: (drop + ;; INLINE-NEXT: (br_if $branch-only + ;; INLINE-NEXT: (i32.const 0) + ;; INLINE-NEXT: (local.get $p) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (i32.const 1) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (catch_all + ;; INLINE-NEXT: (i32.const 2) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (block $both (result i32) + ;; INLINE-NEXT: (try $both0 (result i32) + ;; INLINE-NEXT: (do + ;; INLINE-NEXT: (drop + ;; INLINE-NEXT: (br_if $both + ;; INLINE-NEXT: (i32.const 0) + ;; INLINE-NEXT: (local.get $p) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (try + ;; INLINE-NEXT: (do + ;; INLINE-NEXT: (nop) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (delegate $both0) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (i32.const 1) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: (catch_all + ;; INLINE-NEXT: (i32.const 2) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + ;; INLINE-NEXT: ) + (func $try (param $p i32) (result i32) + (drop + (try $branch-only (result i32) + (do (drop (br_if $branch-only (i32.const 0) (local.get $p))) (i32.const 1)) + (catch_all (i32.const 2)) + ) + ) + (try $both (result i32) + (do + (drop (br_if $both (i32.const 0) (local.get $p))) + (try (do (nop)) (delegate $both)) + (i32.const 1) + ) + (catch_all (i32.const 2)) + ) + ) + + ;; Inlining names the block it creates for the inlined body. That name is + ;; generated, not explicit, so it must not be written. + ;; DEBUG: (func $callee (type $1) (result i32) + ;; DEBUG-NEXT: (i32.const 42) + ;; DEBUG-NEXT: ) + (func $callee (result i32) (i32.const 42)) + ;; DEBUG: (func $caller (type $1) (result i32) + ;; DEBUG-NEXT: (call $callee) + ;; DEBUG-NEXT: ) + ;; INLINE: (func $caller (type $1) (result i32) + ;; INLINE-NEXT: (i32.const 42) + ;; INLINE-NEXT: ) + (func $caller (result i32) (call $callee)) +) +;; NODEBUG: (type $0 (func (param i32) (result i32))) + +;; NODEBUG: (type $1 (func (result i32))) + +;; NODEBUG: (func $0 (type $0) (param $0 i32) (result i32) +;; NODEBUG-NEXT: (drop +;; NODEBUG-NEXT: (i32.const 0) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (block (result i32) +;; NODEBUG-NEXT: (loop $label +;; NODEBUG-NEXT: (br_if $label +;; NODEBUG-NEXT: (local.get $0) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (block $block +;; NODEBUG-NEXT: (br_if $block +;; NODEBUG-NEXT: (local.get $0) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (block +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (block $block1 +;; NODEBUG-NEXT: (if +;; NODEBUG-NEXT: (local.get $0) +;; NODEBUG-NEXT: (then +;; NODEBUG-NEXT: (br $block1) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (i32.const 42) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) + +;; NODEBUG: (func $1 (type $0) (param $0 i32) (result i32) +;; NODEBUG-NEXT: (drop +;; NODEBUG-NEXT: (block $block (result i32) +;; NODEBUG-NEXT: (try (result i32) +;; NODEBUG-NEXT: (do +;; NODEBUG-NEXT: (drop +;; NODEBUG-NEXT: (br_if $block +;; NODEBUG-NEXT: (i32.const 0) +;; NODEBUG-NEXT: (local.get $0) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (i32.const 1) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (catch_all +;; NODEBUG-NEXT: (i32.const 2) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (block $block1 (result i32) +;; NODEBUG-NEXT: (try $label (result i32) +;; NODEBUG-NEXT: (do +;; NODEBUG-NEXT: (drop +;; NODEBUG-NEXT: (br_if $block1 +;; NODEBUG-NEXT: (i32.const 0) +;; NODEBUG-NEXT: (local.get $0) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (try +;; NODEBUG-NEXT: (do +;; NODEBUG-NEXT: (nop) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (delegate $label) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (i32.const 1) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: (catch_all +;; NODEBUG-NEXT: (i32.const 2) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) +;; NODEBUG-NEXT: ) + +;; NODEBUG: (func $2 (type $1) (result i32) +;; NODEBUG-NEXT: (i32.const 42) +;; NODEBUG-NEXT: ) + +;; NODEBUG: (func $3 (type $1) (result i32) +;; NODEBUG-NEXT: (call $2) +;; NODEBUG-NEXT: ) diff --git a/test/lit/blocktype.wast b/test/lit/blocktype.wast index cdd4c084737..2e7ed435be2 100644 --- a/test/lit/blocktype.wast +++ b/test/lit/blocktype.wast @@ -25,7 +25,7 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $f1 (type $f1) (result (ref $f1) (ref $f2)) - ;; RTRIP-NEXT: (loop (type $f1) (result (ref $f1) (ref $f2)) + ;; RTRIP-NEXT: (loop $l (type $f1) (result (ref $f1) (ref $f2)) ;; RTRIP-NEXT: (call $f1) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) @@ -42,8 +42,8 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $f2 (type $f2) (result (ref $f2) (ref $f1)) - ;; RTRIP-NEXT: (loop $label (type $f2) (result (ref $f2) (ref $f1)) - ;; RTRIP-NEXT: (br $label) + ;; RTRIP-NEXT: (loop $block (type $f2) (result (ref $f2) (ref $f1)) + ;; RTRIP-NEXT: (br $block) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) (func $f2 (type $f2) (result (ref $f2) (ref $f1)) diff --git a/test/lit/br_if_cont_uncastable.wast b/test/lit/br_if_cont_uncastable.wast index b33b99989a7..64f15196f34 100644 --- a/test/lit/br_if_cont_uncastable.wast +++ b/test/lit/br_if_cont_uncastable.wast @@ -22,10 +22,10 @@ ) ;; CHECK: (func $br_if_gc (type $3) (param $ref (ref any)) (result anyref) - ;; CHECK-NEXT: (block $block (result anyref) + ;; CHECK-NEXT: (block $label (result anyref) ;; CHECK-NEXT: (call $receive_any ;; CHECK-NEXT: (ref.cast (ref any) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $label ;; CHECK-NEXT: (local.get $ref) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) @@ -51,7 +51,7 @@ ;; CHECK-NEXT: (local $0 (ref (exact $cont))) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $scratch (ref (exact $cont))) - ;; CHECK-NEXT: (block $block (result contref) + ;; CHECK-NEXT: (block $label (result contref) ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (block (result (ref (exact $cont))) ;; CHECK-NEXT: (local.set $scratch @@ -66,7 +66,7 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $label ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) @@ -113,7 +113,7 @@ ;; CHECK-NEXT: (local $scratch_5 (ref any)) ;; CHECK-NEXT: (local $scratch_6 (tuple (ref any) i32)) ;; CHECK-NEXT: (local $scratch_7 (ref any)) - ;; CHECK-NEXT: (block $block (type $8) (result anyref i32) + ;; CHECK-NEXT: (block $label (type $8) (result anyref i32) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (block (result (ref any)) ;; CHECK-NEXT: (local.set $scratch_5 @@ -138,7 +138,7 @@ ;; CHECK-NEXT: (local.set $scratch_7 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch_6 - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $label ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: (local.get $3) @@ -184,7 +184,7 @@ ;; CHECK-NEXT: (local $scratch_4 (ref (exact $cont))) ;; CHECK-NEXT: (local $scratch_5 (tuple (ref (exact $cont)) i32)) ;; CHECK-NEXT: (local $scratch_6 (ref (exact $cont))) - ;; CHECK-NEXT: (block $block (type $2) (result contref i32) + ;; CHECK-NEXT: (block $label (type $2) (result contref i32) ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (block (result (ref (exact $cont))) ;; CHECK-NEXT: (local.set $scratch_4 @@ -211,7 +211,7 @@ ;; CHECK-NEXT: (local.set $scratch_6 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch_5 - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $label ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (local.get $2) diff --git a/test/lit/branch-hinting.wast b/test/lit/branch-hinting.wast index ba8f3716c3f..da69c6abe0a 100644 --- a/test/lit/branch-hinting.wast +++ b/test/lit/branch-hinting.wast @@ -25,8 +25,8 @@ ;; RTRIP: (type $1 (func (param anyref))) ;; RTRIP: (func $no-annotations (type $0) (param $x i32) - ;; RTRIP-NEXT: (block $block - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (block $out + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) @@ -36,8 +36,8 @@ ;; SRCMP: (type $1 (func (param anyref))) ;; SRCMP: (func $no-annotations (type $0) (param $x i32) - ;; SRCMP-NEXT: (block $block - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (block $out + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: ) @@ -69,33 +69,33 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $branch-hints-br_if (type $0) (param $x i32) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (@metadata.code.branch_hint "\00") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: (@metadata.code.branch_hint "\01") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: (@metadata.code.branch_hint "\00") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; SRCMP: (func $branch-hints-br_if (type $0) (param $x i32) - ;; SRCMP-NEXT: (block $block + ;; SRCMP-NEXT: (block $out ;; SRCMP-NEXT: (@metadata.code.branch_hint "\00") - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: (@metadata.code.branch_hint "\01") - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: (@metadata.code.branch_hint "\00") - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: ) @@ -131,18 +131,18 @@ ;; CHECK-NEXT: ) ;; RTRIP: (func $branch_hints-br_if-2 (type $0) (param $x i32) ;; RTRIP-NEXT: (local $unused f64) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (@metadata.code.branch_hint "\01") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; SRCMP: (func $branch_hints-br_if-2 (type $0) (param $x i32) ;; SRCMP-NEXT: (local $unused f64) - ;; SRCMP-NEXT: (block $block + ;; SRCMP-NEXT: (block $out ;; SRCMP-NEXT: (@metadata.code.branch_hint "\01") - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: ) @@ -170,18 +170,18 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $mixing (type $0) (param $x i32) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (@metadata.code.branch_hint "\01") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; SRCMP: (func $mixing (type $0) (param $x i32) ;; SRCMP-NEXT: ;;@ mixing.src:1337:42 - ;; SRCMP-NEXT: (block $block + ;; SRCMP-NEXT: (block $out ;; SRCMP-NEXT: (@metadata.code.branch_hint "\01") - ;; SRCMP-NEXT: (br_if $block + ;; SRCMP-NEXT: (br_if $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: ) @@ -392,20 +392,20 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $branch-hints-br_on (type $1) (param $x anyref) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (drop ;; RTRIP-NEXT: (@metadata.code.branch_hint "\00") - ;; RTRIP-NEXT: (br_on_null $block + ;; RTRIP-NEXT: (br_on_null $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) ;; SRCMP: (func $branch-hints-br_on (type $1) (param $x anyref) - ;; SRCMP-NEXT: (block $block + ;; SRCMP-NEXT: (block $out ;; SRCMP-NEXT: (drop ;; SRCMP-NEXT: (@metadata.code.branch_hint "\00") - ;; SRCMP-NEXT: (br_on_null $block + ;; SRCMP-NEXT: (br_on_null $out ;; SRCMP-NEXT: (local.get $x) ;; SRCMP-NEXT: ) ;; SRCMP-NEXT: ) diff --git a/test/lit/cast-and-recast-tuple.wast b/test/lit/cast-and-recast-tuple.wast index be07847f43c..454d7b96521 100644 --- a/test/lit/cast-and-recast-tuple.wast +++ b/test/lit/cast-and-recast-tuple.wast @@ -19,13 +19,13 @@ ;; CHECK: (func $test-local-tuple-1 (type $2) (param $B (ref $B)) (param $x i32) (result anyref i32) ;; CHECK-NEXT: (local $scratch (tuple (ref $B) i32)) ;; CHECK-NEXT: (local $scratch_3 (ref $B)) - ;; CHECK-NEXT: (block $block (type $3) (result (ref $A) i32) + ;; CHECK-NEXT: (block $out (type $3) (result (ref $A) i32) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (local.set $scratch_3 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (i32.const 3) @@ -70,13 +70,13 @@ ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $scratch (tuple i32 i32)) ;; CHECK-NEXT: (local $scratch_5 i32) - ;; CHECK-NEXT: (block $block (type $6) (result i32 i32) + ;; CHECK-NEXT: (block $out (type $6) (result i32 i32) ;; CHECK-NEXT: (local.set $temp ;; CHECK-NEXT: (block (result i32) ;; CHECK-NEXT: (local.set $scratch_5 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (i32.const -1) ;; CHECK-NEXT: (i32.const 3) @@ -120,13 +120,13 @@ ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $scratch (tuple (ref $B) i32)) ;; CHECK-NEXT: (local $scratch_5 (ref $B)) - ;; CHECK-NEXT: (block $block (type $7) (result (ref $B) i32) + ;; CHECK-NEXT: (block $out (type $7) (result (ref $B) i32) ;; CHECK-NEXT: (local.set $temp ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (local.set $scratch_5 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (i32.const 3) @@ -176,7 +176,7 @@ ;; CHECK-NEXT: (local $scratch_9 (tuple (ref $B) i32)) ;; CHECK-NEXT: (local $scratch_10 (ref $B)) ;; CHECK-NEXT: (local $scratch_11 (ref $B)) - ;; CHECK-NEXT: (block $block (type $3) (result (ref $A) i32) + ;; CHECK-NEXT: (block $out (type $3) (result (ref $A) i32) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (block (result (ref $B)) ;; CHECK-NEXT: (local.set $scratch_8 @@ -201,7 +201,7 @@ ;; CHECK-NEXT: (local.set $scratch_10 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch_9 - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: (local.get $6) @@ -275,7 +275,7 @@ ;; CHECK-NEXT: (local $scratch_17 (ref $B)) ;; CHECK-NEXT: (local $scratch_18 i32) ;; CHECK-NEXT: (local $scratch_19 (ref $B)) - ;; CHECK-NEXT: (block $block (type $8) (result i32 (ref $A) i32) + ;; CHECK-NEXT: (block $out (type $8) (result i32 (ref $A) i32) ;; CHECK-NEXT: (local.set $10 ;; CHECK-NEXT: (block (result i32) ;; CHECK-NEXT: (local.set $scratch_13 @@ -308,7 +308,7 @@ ;; CHECK-NEXT: (local.set $scratch_16 ;; CHECK-NEXT: (tuple.extract 3 0 ;; CHECK-NEXT: (local.tee $scratch_14 - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (tuple.make 3 ;; CHECK-NEXT: (local.get $10) ;; CHECK-NEXT: (local.get $4) diff --git a/test/lit/cast-and-recast.wast b/test/lit/cast-and-recast.wast index ce2af9d9845..d156eb47bb7 100644 --- a/test/lit/cast-and-recast.wast +++ b/test/lit/cast-and-recast.wast @@ -19,9 +19,9 @@ ) ;; CHECK: (func $test (type $3) (param $B (ref $B)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (ref.cast (ref $B) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -41,9 +41,9 @@ ) ;; CHECK: (func $test-cast (type $3) (param $B (ref $B)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (ref.cast (ref $B) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -64,9 +64,9 @@ ) ;; CHECK: (func $test-cast-more (type $3) (param $B (ref $B)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (ref.cast (ref $C) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -87,9 +87,9 @@ ) ;; CHECK: (func $test-cast-less (type $3) (param $B (ref $B)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (ref.cast (ref $B) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -112,10 +112,10 @@ ;; CHECK: (func $test-local (type $3) (param $B (ref $B)) (param $x i32) (result anyref) ;; CHECK-NEXT: (local $temp (ref $B)) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (local.set $temp ;; CHECK-NEXT: (ref.cast (ref $B) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -140,9 +140,9 @@ ) ;; CHECK: (func $test-drop (type $3) (param $B (ref $B)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) + ;; CHECK-NEXT: (block $out (result (ref $A)) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $B) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) @@ -164,8 +164,8 @@ ) ;; CHECK: (func $test-same (type $4) (param $A (ref $A)) (param $x i32) (result anyref) - ;; CHECK-NEXT: (block $block (result (ref $A)) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (block $out (result (ref $A)) + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (local.get $A) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) diff --git a/test/lit/cast-to-basic.wast b/test/lit/cast-to-basic.wast index 7c45cf8a3e4..83a5013b7a7 100644 --- a/test/lit/cast-to-basic.wast +++ b/test/lit/cast-to-basic.wast @@ -33,9 +33,9 @@ ;; CHECK: (func $br (type $0) (param $anyref anyref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block (result structref) + ;; CHECK-NEXT: (block $l (result structref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (br_on_cast $block anyref (ref struct) + ;; CHECK-NEXT: (br_on_cast $l anyref (ref struct) ;; CHECK-NEXT: (local.get $anyref) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) @@ -58,9 +58,9 @@ ;; CHECK: (func $br-null (type $0) (param $anyref anyref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block (result structref) + ;; CHECK-NEXT: (block $l (result structref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (br_on_cast $block anyref structref + ;; CHECK-NEXT: (br_on_cast $l anyref structref ;; CHECK-NEXT: (local.get $anyref) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) @@ -83,9 +83,9 @@ ;; CHECK: (func $br-fail-null (type $0) (param $anyref anyref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block (result anyref) + ;; CHECK-NEXT: (block $l (result anyref) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (br_on_cast_fail $block anyref structref + ;; CHECK-NEXT: (br_on_cast_fail $l anyref structref ;; CHECK-NEXT: (local.get $anyref) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) diff --git a/test/lit/downgrade-reftypes.wast b/test/lit/downgrade-reftypes.wast index 71d009dee0c..fb32b62326b 100644 --- a/test/lit/downgrade-reftypes.wast +++ b/test/lit/downgrade-reftypes.wast @@ -13,29 +13,29 @@ ;; CHECK: (func $foo (type $f) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block (result funcref) - ;; CHECK-NEXT: (br $block + ;; CHECK-NEXT: (block $l1 (result funcref) + ;; CHECK-NEXT: (br $l1 ;; CHECK-NEXT: (ref.func $foo) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block1 (result funcref) - ;; CHECK-NEXT: (br $block1 + ;; CHECK-NEXT: (block $l2 (result funcref) + ;; CHECK-NEXT: (br $l2 ;; CHECK-NEXT: (ref.null nofunc) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block2 (result externref) - ;; CHECK-NEXT: (br $block2 + ;; CHECK-NEXT: (block $l3 (result externref) + ;; CHECK-NEXT: (br $l3 ;; CHECK-NEXT: (ref.null noextern) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block3 (result stringref) - ;; CHECK-NEXT: (br $block3 + ;; CHECK-NEXT: (block $l4 (result stringref) + ;; CHECK-NEXT: (br $l4 ;; CHECK-NEXT: (string.const "hello world") ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) diff --git a/test/lit/multi-hints.wast b/test/lit/multi-hints.wast index 5849f5c0935..18580c4ab26 100644 --- a/test/lit/multi-hints.wast +++ b/test/lit/multi-hints.wast @@ -41,9 +41,9 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $branch (type $0) (param $x i32) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (@metadata.code.branch_hint "\01") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) @@ -68,11 +68,11 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; RTRIP: (func $both (type $0) (param $x i32) - ;; RTRIP-NEXT: (block $block + ;; RTRIP-NEXT: (block $out ;; RTRIP-NEXT: (@metadata.code.inline "\02") ;; RTRIP-NEXT: (call $inline) ;; RTRIP-NEXT: (@metadata.code.branch_hint "\00") - ;; RTRIP-NEXT: (br_if $block + ;; RTRIP-NEXT: (br_if $out ;; RTRIP-NEXT: (local.get $x) ;; RTRIP-NEXT: ) ;; RTRIP-NEXT: ) diff --git a/test/lit/multivalue.wast b/test/lit/multivalue.wast index d9cc14e05ab..f015e91782f 100644 --- a/test/lit/multivalue.wast +++ b/test/lit/multivalue.wast @@ -314,7 +314,7 @@ ;; CHECK-NEXT: (local.set $scratch_1 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch - ;; CHECK-NEXT: (block (type $0) (result i32 i64) + ;; CHECK-NEXT: (block $block (type $0) (result i32 i64) ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (i32.const 42) ;; CHECK-NEXT: (i64.const 42) @@ -381,8 +381,8 @@ ) ;; CHECK: (func $mv-block-break (type $0) (result i32 i64) - ;; CHECK-NEXT: (block $block (type $0) (result i32 i64) - ;; CHECK-NEXT: (br $block + ;; CHECK-NEXT: (block $l (type $0) (result i32 i64) + ;; CHECK-NEXT: (br $l ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (i32.const 42) ;; CHECK-NEXT: (i64.const 42) @@ -402,8 +402,8 @@ ) ;; CHECK: (func $mv-block-br-if (type $0) (result i32 i64) - ;; CHECK-NEXT: (block $block (type $0) (result i32 i64) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (block $l (type $0) (result i32 i64) + ;; CHECK-NEXT: (br_if $l ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (i32.const 42) ;; CHECK-NEXT: (i64.const 42) @@ -481,9 +481,9 @@ ) ;; CHECK: (func $mv-switch (type $0) (result i32 i64) - ;; CHECK-NEXT: (block $block (type $0) (result i32 i64) - ;; CHECK-NEXT: (block $block1 (type $0) (result i32 i64) - ;; CHECK-NEXT: (br_table $block $block1 + ;; CHECK-NEXT: (block $a (type $0) (result i32 i64) + ;; CHECK-NEXT: (block $b (type $0) (result i32 i64) + ;; CHECK-NEXT: (br_table $a $b ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (i32.const 42) ;; CHECK-NEXT: (i64.const 42) diff --git a/test/lit/passes/asyncify_pass-arg=asyncify-eh-asserts.wast b/test/lit/passes/asyncify_pass-arg=asyncify-eh-asserts.wast index 59c31c447ca..bc5e1f6dba6 100644 --- a/test/lit/passes/asyncify_pass-arg=asyncify-eh-asserts.wast +++ b/test/lit/passes/asyncify_pass-arg=asyncify-eh-asserts.wast @@ -93,8 +93,8 @@ ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (then - ;; CHECK-NEXT: (block $label - ;; CHECK-NEXT: (try $try1 + ;; CHECK-NEXT: (block $try1 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $0) @@ -104,7 +104,7 @@ ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (br_if $label + ;; CHECK-NEXT: (br_if $try1 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block @@ -196,7 +196,7 @@ ;; CHECK-NEXT: (local.get $10) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (br_if $label + ;; CHECK-NEXT: (br_if $try1 ;; CHECK-NEXT: (local.get $11) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block @@ -372,8 +372,8 @@ ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (then - ;; CHECK-NEXT: (block $label - ;; CHECK-NEXT: (try $try1 + ;; CHECK-NEXT: (block $try1 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do @@ -385,7 +385,7 @@ ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (br_if $label + ;; CHECK-NEXT: (br_if $try1 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block @@ -561,7 +561,7 @@ ;; CHECK-NEXT: (local.get $14) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (br_if $label + ;; CHECK-NEXT: (br_if $try1 ;; CHECK-NEXT: (local.get $15) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block @@ -587,7 +587,7 @@ ;; CHECK-NEXT: (local.get $16) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (br_if $label + ;; CHECK-NEXT: (br_if $try1 ;; CHECK-NEXT: (local.get $17) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block diff --git a/test/lit/passes/code-pushing-eh-legacy.wast b/test/lit/passes/code-pushing-eh-legacy.wast index 74cedc5f6ca..19f03af0dfc 100644 --- a/test/lit/passes/code-pushing-eh-legacy.wast +++ b/test/lit/passes/code-pushing-eh-legacy.wast @@ -209,7 +209,7 @@ ;; CHECK-NEXT: (local.set $x ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (try $l + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index 173d086e918..65e6eaa956f 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -1988,7 +1988,7 @@ ) ;; CHECK: (func $empty-tag (type $0) - ;; CHECK-NEXT: (try $label$3 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) diff --git a/test/lit/passes/inlining-eh-legacy.wast b/test/lit/passes/inlining-eh-legacy.wast index ac59e520211..8864ea68d47 100644 --- a/test/lit/passes/inlining-eh-legacy.wast +++ b/test/lit/passes/inlining-eh-legacy.wast @@ -23,7 +23,7 @@ ;; CHECK: (func $caller-with-label (type $1) (param $x i32) ;; CHECK-NEXT: (loop $label ;; CHECK-NEXT: (block $__inlined_func$callee-with-label - ;; CHECK-NEXT: (try $label0 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch $tag$0 @@ -49,7 +49,7 @@ ;; --------------------------------------------------------------------------- ;; CHECK: (func $callee-with-try-delegate (type $0) - ;; CHECK-NEXT: (try $label$3 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate 0) @@ -79,7 +79,7 @@ ;; Properly support inlining into a function with a try-delegate ;; CHECK: (func $caller-with-try-delegate (type $2) (result i32) - ;; CHECK-NEXT: (try $label$3 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate 0) diff --git a/test/lit/passes/once-reduction.wast b/test/lit/passes/once-reduction.wast index 4cf6fd9b81e..567db37cd5d 100644 --- a/test/lit/passes/once-reduction.wast +++ b/test/lit/passes/once-reduction.wast @@ -1213,7 +1213,7 @@ ) ;; CHECK: (func $try-catch (type $0) - ;; CHECK-NEXT: (try $label$5 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 1) diff --git a/test/lit/passes/roundtrip.wast b/test/lit/passes/roundtrip.wast index 21aa1f67160..f9abf9801f5 100644 --- a/test/lit/passes/roundtrip.wast +++ b/test/lit/passes/roundtrip.wast @@ -12,7 +12,7 @@ ;; CHECK-NEXT: (local.set $scratch_1 ;; CHECK-NEXT: (tuple.extract 2 0 ;; CHECK-NEXT: (local.tee $scratch - ;; CHECK-NEXT: (block (type $1) (result funcref (ref $none)) + ;; CHECK-NEXT: (block $block (type $1) (result funcref (ref $none)) ;; CHECK-NEXT: (tuple.make 2 ;; CHECK-NEXT: (ref.null nofunc) ;; CHECK-NEXT: (ref.func $foo) diff --git a/test/lit/passes/rse-eh-legacy.wast b/test/lit/passes/rse-eh-legacy.wast index f90da4643d4..5b74ca75fc6 100644 --- a/test/lit/passes/rse-eh-legacy.wast +++ b/test/lit/passes/rse-eh-legacy.wast @@ -586,7 +586,7 @@ ;; CHECK: (func $try-delegate2 (type $0) ;; CHECK-NEXT: (local $x i32) - ;; CHECK-NEXT: (try $l0 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do diff --git a/test/lit/passes/signature-pruning.wast b/test/lit/passes/signature-pruning.wast index d86e855dbe8..d90267b00cb 100644 --- a/test/lit/passes/signature-pruning.wast +++ b/test/lit/passes/signature-pruning.wast @@ -984,7 +984,7 @@ ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block $block (result i32) - ;; CHECK-NEXT: (try $try + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) @@ -1071,7 +1071,7 @@ ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block $block (result i32) - ;; CHECK-NEXT: (try $try + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) diff --git a/test/lit/passes/stack-ir-eh-legacy.wast b/test/lit/passes/stack-ir-eh-legacy.wast index a8b30987538..76bf0ac0175 100644 --- a/test/lit/passes/stack-ir-eh-legacy.wast +++ b/test/lit/passes/stack-ir-eh-legacy.wast @@ -23,7 +23,7 @@ ;; CHECK-NEXT: unreachable ;; CHECK-NEXT: catch_all ;; CHECK-NEXT: end - ;; CHECK-NEXT: try $l01 + ;; CHECK-NEXT: try ;; CHECK-NEXT: delegate 0 ;; CHECK-NEXT: ) (func $eh diff --git a/test/lit/passes/vacuum-tnh.wast b/test/lit/passes/vacuum-tnh.wast index 89d96a562df..384e1414f2f 100644 --- a/test/lit/passes/vacuum-tnh.wast +++ b/test/lit/passes/vacuum-tnh.wast @@ -651,7 +651,7 @@ ) ;; YESTNH: (func $catch-pop (type $0) - ;; YESTNH-NEXT: (try $try + ;; YESTNH-NEXT: (try ;; YESTNH-NEXT: (do ;; YESTNH-NEXT: (call $catch-pop) ;; YESTNH-NEXT: ) @@ -664,7 +664,7 @@ ;; YESTNH-NEXT: ) ;; YESTNH-NEXT: ) ;; NO_TNH: (func $catch-pop (type $0) - ;; NO_TNH-NEXT: (try $try + ;; NO_TNH-NEXT: (try ;; NO_TNH-NEXT: (do ;; NO_TNH-NEXT: (call $catch-pop) ;; NO_TNH-NEXT: ) diff --git a/test/lit/reftypes-without-gc.wast b/test/lit/reftypes-without-gc.wast index d251d0e0b84..4e112100521 100644 --- a/test/lit/reftypes-without-gc.wast +++ b/test/lit/reftypes-without-gc.wast @@ -10,8 +10,8 @@ (module ;; CHECK: (func $test (param $x i32) (result funcref) - ;; CHECK-NEXT: (block $block (result funcref) - ;; CHECK-NEXT: (br_if $block + ;; CHECK-NEXT: (block $out (result funcref) + ;; CHECK-NEXT: (br_if $out ;; CHECK-NEXT: (ref.func $test) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) diff --git a/test/lit/source-map.wast b/test/lit/source-map.wast index fe534043bd3..223c206a97d 100644 --- a/test/lit/source-map.wast +++ b/test/lit/source-map.wast @@ -65,10 +65,10 @@ ;; CHECK: (func $nested-blocks ;; CHECK-NEXT: ;;@ src.cpp:2:1 - ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (block $label$1 ;; CHECK-NEXT: ;;@ src.cpp:2:2 - ;; CHECK-NEXT: (block $block - ;; CHECK-NEXT: (br $block) + ;; CHECK-NEXT: (block $label$2 + ;; CHECK-NEXT: (br $label$2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ;;@ src.cpp:3:1 diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 0b04d385961..f81b6c55060 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -2105,7 +2105,7 @@ ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do ;; CHECK-NEXT: (block $l0 - ;; CHECK-NEXT: (try $l1 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l) @@ -2126,11 +2126,11 @@ ;; CHECK: (func $try-delegate-nested-catch-shadowing (type $0) ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do - ;; CHECK-NEXT: (try $l0 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch $empty - ;; CHECK-NEXT: (try $l1 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l) @@ -2154,11 +2154,11 @@ ;; CHECK: (func $try-delegate-nested-catch_all-shadowing (type $0) ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do - ;; CHECK-NEXT: (try $l0 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch_all - ;; CHECK-NEXT: (try $l1 + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l) @@ -2205,16 +2205,16 @@ ) ;; CHECK: (func $try-br-name (type $0) - ;; CHECK-NEXT: (block $label - ;; CHECK-NEXT: (try $l + ;; CHECK-NEXT: (block $l + ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do - ;; CHECK-NEXT: (br $label) + ;; CHECK-NEXT: (br $l) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch $empty - ;; CHECK-NEXT: (br $label) + ;; CHECK-NEXT: (br $l) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch_all - ;; CHECK-NEXT: (br $label) + ;; CHECK-NEXT: (br $l) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) From 198adc726f87a2f891b832288000155e8d66d1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Mon, 28 Sep 2026 22:09:38 +0200 Subject: [PATCH 3/5] Changes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6cab75178f..42537ea3595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Current Trunk - Add a new wasm-embed tool for extracting Wasm modules embedded as byte arrays in JS source files or replacing such modules in the JS source (#9127) + - Support reading and writing label names in the name section (#9166) v133 ---- From ac23c0e8f02d36b75e69a23448c7ba0f0dfd7ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 29 Sep 2026 12:01:24 +0200 Subject: [PATCH 4/5] Move helper functions at a more appropriate place --- src/wasm-binary.h | 16 +++++++++++----- src/wasm-ir-builder.h | 10 +++++----- src/wasm-stack.h | 12 ++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 99aef564b7c..ae34b277adf 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1438,8 +1438,6 @@ class WasmBinaryWriter { void writeFunctionSignatures(); void writeExpression(Expression* curr); void writeFunctions(); - void noteLabelNames(Function* func, - std::vector>& labelNames); void writeStrings(); void writeGlobals(); void writeExports(); @@ -1582,6 +1580,14 @@ class WasmBinaryWriter { void prepare(); + // Internal helper for recording the label names of a function once its code + // has been written, so that they can be emitted in the name section later. + // `labelNames` holds (label index, name) pairs for the function's explicitly + // named labels, as gathered by the function writer; its contents are moved + // into `funcLabelNames`, and nothing is recorded if it is empty. + void noteLabelNames(Function* func, + std::vector>& labelNames); + // Internal helper for emitting a code annotation section for a hint that is // expression offset based. Receives the name of the section and two // functions, one to check if the annotation we care about exists (receiving @@ -1759,9 +1765,6 @@ class WasmBinaryReader { const std::unordered_map* currLabelNames = nullptr; Index nextLabelIndex = 0; - // Returns the name the name section gives to the next label of the current - // function, or a null name if it has none, and advances the label index. - Name getNextLabelName(); // before we see a function (like global init expressions), there is no end of // function to check Index endOfFunction = -1; @@ -1773,6 +1776,9 @@ class WasmBinaryReader { void readVars(); void setLocalNames(Function& func, Index i); void setLabelNames(Index i); + // Returns the name the name section gives to the next label of the current + // function, or a null name if it has none, and advances the label index. + Name getNextLabelName(); Result<> readInst(); diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 66b6c6d912b..91a1d544c64 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -428,9 +428,9 @@ class IRBuilder : public UnifiedExpressionVisitor> { // For Try scopes with a label in the text format, the fresh version of that // label, reserved for whichever of `label` and `branchLabel` is needed - // first. Most tries are only targeted by branches, and giving the name to - // the delegate label up front would leave the branch label with a - // generated name. + // first, or for `label` if neither is used by the end of the try. Most + // tries are only targeted by branches, and giving the name to the delegate + // label up front would leave the branch label with a generated name. Name reservedLabel; bool labelUsed = false; @@ -711,8 +711,8 @@ class IRBuilder : public UnifiedExpressionVisitor> { Result<> pushScope(ScopeCtx&& scope) { if (auto label = scope.getOriginalLabel()) { // Assign a fresh label to the scope, if necessary. The labels of a try - // are only assigned when they are used, and catches keep the labels of - // their try. + // are only assigned when they are used (or when the try ends), and + // catches keep the labels of their try. if (scope.getTry()) { scope.reservedLabel = makeFresh(label); scope.nameHint = label; diff --git a/src/wasm-stack.h b/src/wasm-stack.h index 90149c65250..9df191b204d 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -127,12 +127,6 @@ class BinaryInstWriter : public OverriddenVisitor { void emitUnreachableLocalSet(Index index); void mapLocalsAndEmitHeader(); - // Note the start of a scope: every block, loop, if, try and try_table takes - // an index in the function's label index space, in the order they appear in - // the function body, whether or not they have a name. Records the explicitly - // named ones for the name section. - void noteScopeStart(Name name = Name()); - MappedLocals mappedLocals; // The explicitly named labels of this function, as (label index, name). @@ -142,6 +136,12 @@ class BinaryInstWriter : public OverriddenVisitor { // The index the next scope in this function will take. Index nextLabelIndex = 0; + // Note the start of a scope: every block, loop, if, try and try_table takes + // an index in the function's label index space, in the order they appear in + // the function body, whether or not they have a name. Records the explicitly + // named ones for the name section. + void noteScopeStart(Name name = Name()); + void emitMemoryAccess(size_t alignment, size_t bytes, uint64_t offset, From 281ea7ee6b77a35e81194dd1fd1f7a8a372f61a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 29 Sep 2026 12:02:50 +0200 Subject: [PATCH 5/5] Preserve labels on try --- src/wasm/wasm-ir-builder.cpp | 5 +++++ test/lit/passes/code-pushing-eh-legacy.wast | 2 +- test/lit/passes/gufa-refs.wast | 2 +- test/lit/passes/inlining-eh-legacy.wast | 6 +++--- test/lit/passes/once-reduction.wast | 2 +- test/lit/passes/rse-eh-legacy.wast | 2 +- test/lit/passes/signature-pruning.wast | 4 ++-- test/lit/passes/stack-ir-eh-legacy.wast | 2 +- test/lit/passes/vacuum-tnh.wast | 4 ++-- test/lit/wat-kitchen-sink.wast | 10 +++++----- 10 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 3e0556c7e2c..e889bad88e6 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -1132,6 +1132,11 @@ Result<> IRBuilder::visitEnd() { CHECK_ERR(expr); bool isTry = scope.getTry() || scope.getCatch() || scope.getCatchAll(); + // If the reserved label of a try was not taken by a branch or a delegate, + // give it to the try itself so the name is not lost. + if (isTry && !scope.label) { + scope.label = std::exchange(scope.reservedLabel, Name()); + } auto& label = isTry ? scope.branchLabel : scope.label; auto blockType = scope.getResultType(); diff --git a/test/lit/passes/code-pushing-eh-legacy.wast b/test/lit/passes/code-pushing-eh-legacy.wast index 19f03af0dfc..74cedc5f6ca 100644 --- a/test/lit/passes/code-pushing-eh-legacy.wast +++ b/test/lit/passes/code-pushing-eh-legacy.wast @@ -209,7 +209,7 @@ ;; CHECK-NEXT: (local.set $x ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index 65e6eaa956f..173d086e918 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -1988,7 +1988,7 @@ ) ;; CHECK: (func $empty-tag (type $0) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $label$3 ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) diff --git a/test/lit/passes/inlining-eh-legacy.wast b/test/lit/passes/inlining-eh-legacy.wast index 8864ea68d47..ac59e520211 100644 --- a/test/lit/passes/inlining-eh-legacy.wast +++ b/test/lit/passes/inlining-eh-legacy.wast @@ -23,7 +23,7 @@ ;; CHECK: (func $caller-with-label (type $1) (param $x i32) ;; CHECK-NEXT: (loop $label ;; CHECK-NEXT: (block $__inlined_func$callee-with-label - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $label0 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch $tag$0 @@ -49,7 +49,7 @@ ;; --------------------------------------------------------------------------- ;; CHECK: (func $callee-with-try-delegate (type $0) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $label$3 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate 0) @@ -79,7 +79,7 @@ ;; Properly support inlining into a function with a try-delegate ;; CHECK: (func $caller-with-try-delegate (type $2) (result i32) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $label$3 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate 0) diff --git a/test/lit/passes/once-reduction.wast b/test/lit/passes/once-reduction.wast index 567db37cd5d..4cf6fd9b81e 100644 --- a/test/lit/passes/once-reduction.wast +++ b/test/lit/passes/once-reduction.wast @@ -1213,7 +1213,7 @@ ) ;; CHECK: (func $try-catch (type $0) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $label$5 ;; CHECK-NEXT: (do ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 1) diff --git a/test/lit/passes/rse-eh-legacy.wast b/test/lit/passes/rse-eh-legacy.wast index 5b74ca75fc6..f90da4643d4 100644 --- a/test/lit/passes/rse-eh-legacy.wast +++ b/test/lit/passes/rse-eh-legacy.wast @@ -586,7 +586,7 @@ ;; CHECK: (func $try-delegate2 (type $0) ;; CHECK-NEXT: (local $x i32) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l0 ;; CHECK-NEXT: (do ;; CHECK-NEXT: (try ;; CHECK-NEXT: (do diff --git a/test/lit/passes/signature-pruning.wast b/test/lit/passes/signature-pruning.wast index d90267b00cb..d86e855dbe8 100644 --- a/test/lit/passes/signature-pruning.wast +++ b/test/lit/passes/signature-pruning.wast @@ -984,7 +984,7 @@ ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block $block (result i32) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) @@ -1071,7 +1071,7 @@ ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block $block (result i32) - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $try ;; CHECK-NEXT: (do ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) diff --git a/test/lit/passes/stack-ir-eh-legacy.wast b/test/lit/passes/stack-ir-eh-legacy.wast index 76bf0ac0175..a8b30987538 100644 --- a/test/lit/passes/stack-ir-eh-legacy.wast +++ b/test/lit/passes/stack-ir-eh-legacy.wast @@ -23,7 +23,7 @@ ;; CHECK-NEXT: unreachable ;; CHECK-NEXT: catch_all ;; CHECK-NEXT: end - ;; CHECK-NEXT: try + ;; CHECK-NEXT: try $l01 ;; CHECK-NEXT: delegate 0 ;; CHECK-NEXT: ) (func $eh diff --git a/test/lit/passes/vacuum-tnh.wast b/test/lit/passes/vacuum-tnh.wast index 384e1414f2f..89d96a562df 100644 --- a/test/lit/passes/vacuum-tnh.wast +++ b/test/lit/passes/vacuum-tnh.wast @@ -651,7 +651,7 @@ ) ;; YESTNH: (func $catch-pop (type $0) - ;; YESTNH-NEXT: (try + ;; YESTNH-NEXT: (try $try ;; YESTNH-NEXT: (do ;; YESTNH-NEXT: (call $catch-pop) ;; YESTNH-NEXT: ) @@ -664,7 +664,7 @@ ;; YESTNH-NEXT: ) ;; YESTNH-NEXT: ) ;; NO_TNH: (func $catch-pop (type $0) - ;; NO_TNH-NEXT: (try + ;; NO_TNH-NEXT: (try $try ;; NO_TNH-NEXT: (do ;; NO_TNH-NEXT: (call $catch-pop) ;; NO_TNH-NEXT: ) diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index f81b6c55060..80b86f7cffe 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -2105,7 +2105,7 @@ ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do ;; CHECK-NEXT: (block $l0 - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l1 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l) @@ -2126,11 +2126,11 @@ ;; CHECK: (func $try-delegate-nested-catch-shadowing (type $0) ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l0 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch $empty - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l1 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l) @@ -2154,11 +2154,11 @@ ;; CHECK: (func $try-delegate-nested-catch_all-shadowing (type $0) ;; CHECK-NEXT: (try $l ;; CHECK-NEXT: (do - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l0 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (catch_all - ;; CHECK-NEXT: (try + ;; CHECK-NEXT: (try $l1 ;; CHECK-NEXT: (do ;; CHECK-NEXT: ) ;; CHECK-NEXT: (delegate $l)