Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 0.4.13 (unreleased)

Bugfixes:
* Code Generator: Correctly unregister modifier variables.

### 0.4.12 (2017-07-03)

Features:
Expand Down
3 changes: 3 additions & 0 deletions libsolidity/codegen/ContractCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,10 @@ void ContractCompiler::appendModifierOrFunctionCode()
);
}
for (VariableDeclaration const* localVariable: modifier.localVariables())
{
addedVariables.push_back(localVariable);
appendStackVariableInitialisation(*localVariable);
}

stackSurplus =
CompilerUtils::sizeOnStack(modifier.parameters()) +
Expand Down
27 changes: 27 additions & 0 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9696,6 +9696,33 @@ BOOST_AUTO_TEST_CASE(keccak256_assembly)
BOOST_CHECK(callContractFunction("i()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
}

BOOST_AUTO_TEST_CASE(multi_modifiers)
{
// This triggered a bug in some version because the variable in the modifier was not
// unregistered correctly.
char const* sourceCode = R"(
contract C {
uint public x;
modifier m1 {
address a1 = msg.sender;
x++;
_;
}
function f1() m1() {
x += 7;
}
function f2() m1() {
x += 3;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f1()") == bytes());
BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(8)));
BOOST_CHECK(callContractFunction("f2()") == bytes());
BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(12)));
}

BOOST_AUTO_TEST_SUITE_END()

}
Expand Down