From 8e208f23cba81f965b178a076de2e2f4c144a70d Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 28 Oct 2021 16:25:43 +0200 Subject: [PATCH] Fix assignment of return variables from modifiers. --- Changelog.md | 3 +++ libsolidity/codegen/ir/IRGenerator.cpp | 4 ++-- .../function_modifier_return_reference.sol | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/semanticTests/modifiers/function_modifier_return_reference.sol diff --git a/Changelog.md b/Changelog.md index ff183e22b..4cfbe6637 100644 --- a/Changelog.md +++ b/Changelog.md @@ -29,6 +29,9 @@ Bugfixes: * Yul IR Generator: Do not output empty switches/if-bodies for empty contracts. +Important Bugfixes in Experimental Features: + * Yul IR Generator: Changes to function return variables referenced in modifier invocation arguments were not properly forwarded if there was more than one return variable. + ### 0.8.9 (2021-09-29) diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 44cd534ff..b17b33c03 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -438,7 +438,7 @@ string IRGenerator::generateModifier( for (size_t i = 0; i < retParamsIn.size(); ++i) { retParams.emplace_back(m_context.newYulVariable()); - assignRetParams += retParams.back() + " := " + retParamsIn[i] + "\n"; + assignRetParams += retParams.at(i) + " := " + retParamsIn.at(i) + "\n"; } t("retParams", joinHumanReadable(retParams)); t("assignRetParams", assignRetParams); @@ -529,7 +529,7 @@ string IRGenerator::generateFunctionWithModifierInner(FunctionDefinition const& for (size_t i = 0; i < retParams.size(); ++i) { retParamsIn.emplace_back(m_context.newYulVariable()); - assignRetParams += retParams.back() + " := " + retParamsIn[i] + "\n"; + assignRetParams += retParams.at(i) + " := " + retParamsIn.at(i) + "\n"; } vector params = retParamsIn; for (auto const& varDecl: _function.parameters()) diff --git a/test/libsolidity/semanticTests/modifiers/function_modifier_return_reference.sol b/test/libsolidity/semanticTests/modifiers/function_modifier_return_reference.sol new file mode 100644 index 000000000..1da6c011d --- /dev/null +++ b/test/libsolidity/semanticTests/modifiers/function_modifier_return_reference.sol @@ -0,0 +1,15 @@ +contract C { + modifier m1(uint value) { + _; + } + modifier m2(uint value) { + _; + } + + function f() public m1(x = 2) m2(y = 3) returns (uint x, uint y) { + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> 2, 3