From 64ddb176bb71498f3a129e0cc549797f4138ec1f Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 29 May 2017 20:32:47 +0200 Subject: Test for accessing outer inline assembly scope. --- test/libsolidity/SolidityEndToEndTest.cpp | 27 +++++++++++++++++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 35 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bb8ec112..212c5111 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -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"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 16e2dea4..db5b9bf8 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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) -- cgit v1.2.3