diff options
author | Thomas Lively <tlively@google.com> | 2024-01-05 17:54:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-05 17:54:40 -0800 |
commit | c3b2f245fe27b933a97e732b12bdf1eb1a0f39b7 (patch) | |
tree | e02b439a832d158dda44adce00b67381ab805743 /src/wasm/wasm-ir-builder.cpp | |
parent | 436d6399d2e915490f980f7f8193e84dc7ed215f (diff) | |
download | binaryen-c3b2f245fe27b933a97e732b12bdf1eb1a0f39b7.tar.gz binaryen-c3b2f245fe27b933a97e732b12bdf1eb1a0f39b7.tar.bz2 binaryen-c3b2f245fe27b933a97e732b12bdf1eb1a0f39b7.zip |
Fix branches to loops in IRBuilder (#6205)
Since branches to loops go to the beginnings of the loops, they should send
values matching the input types for the loops (which are always none because we
don't support loop input types). IRBuilder was previously using the output types
of loops to determine what values the branches should carry, which was
incorrect. Fix it.
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index e8a2a2386..dc80d6af5 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -414,15 +414,18 @@ Result<Expression*> IRBuilder::getBranchValue(Name labelName, } auto scope = getScope(*label); CHECK_ERR(scope); - std::vector<Expression*> values((*scope)->getResultType().size()); - for (size_t i = 0, size = values.size(); i < size; ++i) { + // Loops would receive their input type rather than their output type, if we + // supported that. + size_t numValues = (*scope)->getLoop() ? 0 : (*scope)->getResultType().size(); + std::vector<Expression*> values(numValues); + for (size_t i = 0; i < numValues; ++i) { auto val = pop(); CHECK_ERR(val); - values[size - 1 - i] = *val; + values[numValues - 1 - i] = *val; } - if (values.size() == 0) { + if (numValues == 0) { return nullptr; - } else if (values.size() == 1) { + } else if (numValues == 1) { return values[0]; } else { return builder.makeTupleMake(values); |