mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Test for accessing outer inline assembly scope.
This commit is contained in:
parent
97cc968a13
commit
64ddb176bb
@ -7462,6 +7462,33 @@ BOOST_AUTO_TEST_CASE(inline_assembly_storage_access)
|
||||
BOOST_CHECK(callContractFunction("z()") == encodeArgs(u256(7)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_inside_function)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
uint16 x;
|
||||
uint16 public y;
|
||||
uint public z;
|
||||
function f() returns (bool) {
|
||||
uint off1;
|
||||
uint off2;
|
||||
assembly {
|
||||
function f() -> o1 {
|
||||
sstore(z_slot, 7)
|
||||
o1 := y_offset
|
||||
}
|
||||
off2 := f()
|
||||
}
|
||||
assert(off2 == 2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("z()") == encodeArgs(u256(7)));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_storage_access_via_pointer)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
@ -5159,7 +5159,7 @@ BOOST_AUTO_TEST_CASE(inline_assembly_constant_access)
|
||||
CHECK_ERROR(text, TypeError, "Constant variables not supported by inline assembly");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_variable_access_out_of_functions)
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_local_variable_access_out_of_functions)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
@ -5171,7 +5171,38 @@ BOOST_AUTO_TEST_CASE(inline_assembly_variable_access_out_of_functions)
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, DeclarationError, "Inline assembly functions cannot access their outer scope.");
|
||||
CHECK_ERROR(text, DeclarationError, "Cannot access local Solidity variables from inside an inline assembly function.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_local_variable_access_out_of_functions_storage_ptr)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
uint[] r;
|
||||
function f() {
|
||||
uint[] storage a = r;
|
||||
assembly {
|
||||
function g() -> x { x := a_offset }
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, DeclarationError, "Cannot access local Solidity variables from inside an inline assembly function.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(inline_assembly_storage_variable_access_out_of_functions)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
uint a;
|
||||
function f() {
|
||||
assembly {
|
||||
function g() -> x { x := a_slot }
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(invalid_mobile_type)
|
||||
|
Loading…
Reference in New Issue
Block a user