Merge pull request #1261 from ethereum/inline-assembly-in-modifiers

Fix inline assembly variable access within modifiers
This commit is contained in:
chriseth 2016-10-21 11:27:36 +02:00 committed by GitHub
commit 984b8ac1b5
4 changed files with 75 additions and 1 deletions

View File

@ -16,6 +16,7 @@ Bugfixes:
* Inline assembly: fix parsing of assignment after a label.
* Inline assembly: external variables of unsupported type (such as ``this``, ``super``, etc.)
are properly detected as unusable.
* Inline assembly: support variables within modifiers.
### 0.4.2 (2016-09-17)

View File

@ -623,7 +623,7 @@ public:
virtual bool isLValue() const override;
virtual bool isPartOfExternalInterface() const override { return isPublic(); }
bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(scope()); }
bool isLocalVariable() const { return !!dynamic_cast<CallableDeclaration const*>(scope()); }
/// @returns true if this variable is a parameter or return parameter of a function.
bool isCallableParameter() const;
/// @returns true if this variable is a parameter (not return parameter) of an external function.

View File

@ -7304,6 +7304,28 @@ BOOST_AUTO_TEST_CASE(shift_negative_constant_right)
BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x42)));
}
BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers)
{
char const* sourceCode = R"(
contract C {
modifier m {
uint a = 1;
assembly {
a := 2
}
if (a != 2)
throw;
_;
}
function f() m returns (bool) {
return true;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
}
BOOST_AUTO_TEST_SUITE_END()
}

View File

@ -4107,6 +4107,57 @@ BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_negative_stack)
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
}
BOOST_AUTO_TEST_CASE(inline_assembly_in_modifier)
{
char const* text = R"(
contract test {
modifier m {
uint a = 1;
assembly {
a := 2
}
_;
}
function f() m {
}
}
)";
BOOST_CHECK(success(text));
}
BOOST_AUTO_TEST_CASE(inline_assembly_storage)
{
char const* text = R"(
contract test {
uint x = 1;
function f() {
assembly {
x := 2
}
}
}
)";
BOOST_CHECK(expectError(text, false) == Error::Type::DeclarationError);
}
BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers)
{
char const* text = R"(
contract test {
uint x = 1;
modifier m {
assembly {
x := 2
}
_;
}
function f() m {
}
}
)";
BOOST_CHECK(expectError(text, false) == Error::Type::DeclarationError);
}
BOOST_AUTO_TEST_SUITE_END()
}