From 6d15c229fa03cda85b9db90d2ef2cbd8ac7d4143 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 13 Apr 2021 12:26:13 +0200 Subject: [PATCH] Support multi-variable-declarations without value. --- libyul/optimiser/StackToMemoryMover.cpp | 16 +++++++++----- ...lti_variable_declaration_without_value.yul | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/libyul/yulOptimizerTests/fakeStackLimitEvader/multi_variable_declaration_without_value.yul diff --git a/libyul/optimiser/StackToMemoryMover.cpp b/libyul/optimiser/StackToMemoryMover.cpp index 04b3cd0e4..7c859bfba 100644 --- a/libyul/optimiser/StackToMemoryMover.cpp +++ b/libyul/optimiser/StackToMemoryMover.cpp @@ -213,11 +213,17 @@ void StackToMemoryMover::operator()(Block& _block) else return {}; } - FunctionCall const* functionCall = get_if(_stmt.value.get()); - yulAssert(functionCall, ""); - auto rhsMemorySlots = m_functionReturnVariables.at(functionCall->functionName.name) | - ranges::views::transform(m_memoryOffsetTracker) | - ranges::to>>; + vector> rhsMemorySlots; + if (_stmt.value) + { + FunctionCall const* functionCall = get_if(_stmt.value.get()); + yulAssert(functionCall, ""); + rhsMemorySlots = m_functionReturnVariables.at(functionCall->functionName.name) | + ranges::views::transform(m_memoryOffsetTracker) | + ranges::to>>; + } + else + rhsMemorySlots = vector>(_lhsVars.size(), nullopt); // Nothing to do, if the right-hand-side remains entirely on the stack and // none of the variables in the left-hand-side are moved. diff --git a/test/libyul/yulOptimizerTests/fakeStackLimitEvader/multi_variable_declaration_without_value.yul b/test/libyul/yulOptimizerTests/fakeStackLimitEvader/multi_variable_declaration_without_value.yul new file mode 100644 index 000000000..5650b580d --- /dev/null +++ b/test/libyul/yulOptimizerTests/fakeStackLimitEvader/multi_variable_declaration_without_value.yul @@ -0,0 +1,21 @@ +{ + mstore(0x40, memoryguard(0x60)) + { + let x, y + } + { + let z, $w + } +} +// ---- +// step: fakeStackLimitEvader +// +// { +// mstore(0x40, memoryguard(0x80)) +// { let x, y } +// { +// let z_1, $w_2 +// mstore(0x60, $w_2) +// let z := z_1 +// } +// }