From 86be0fbc2fa242bc56302984675b3bec4b18fc07 Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Tue, 16 Jun 2020 21:23:26 -0500 Subject: [PATCH] [ewasm] Fix infinite loops. --- Changelog.md | 1 + libyul/backends/wasm/WasmCodeTransform.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 91a7fc43f..9328f2824 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Bugfixes: * NatSpec: Do not consider ``////`` and ``/***`` as NatSpec comments. * Type Checker: Fix internal error related to ``using for`` applied to non-libraries. * Type Checker: Do not disallow assigning to calldata variables. + * Wasm backend: Fix code generation for for-loops with pre statements. * Yul: Fix source location of variable multi-assignment. diff --git a/libyul/backends/wasm/WasmCodeTransform.cpp b/libyul/backends/wasm/WasmCodeTransform.cpp index d2bceaa90..5171db1b1 100644 --- a/libyul/backends/wasm/WasmCodeTransform.cpp +++ b/libyul/backends/wasm/WasmCodeTransform.cpp @@ -257,9 +257,10 @@ wasm::Expression WasmCodeTransform::operator()(ForLoop const& _for) YulString eqz_instruction = YulString(conditionType.str() + ".eqz"); yulAssert(WasmDialect::instance().builtin(eqz_instruction), ""); + std::vector statements = visit(_for.pre.statements); + wasm::Loop loop; loop.labelName = newLabel(); - loop.statements = visit(_for.pre.statements); loop.statements.emplace_back(wasm::BranchIf{wasm::Label{breakLabel}, make_unique( wasm::BuiltinCall{eqz_instruction.str(), make_vector( visitReturnByValue(*_for.condition) @@ -269,7 +270,8 @@ wasm::Expression WasmCodeTransform::operator()(ForLoop const& _for) loop.statements += visit(_for.post.statements); loop.statements.emplace_back(wasm::Branch{wasm::Label{loop.labelName}}); - return { wasm::Block{breakLabel, make_vector(move(loop))} }; + statements += make_vector(move(loop)); + return wasm::Block{breakLabel, move(statements)}; } wasm::Expression WasmCodeTransform::operator()(Break const&)