aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-05-30 02:32:47 +0800
committerchriseth <chris@ethereum.org>2017-06-08 21:52:45 +0800
commit64ddb176bb71498f3a129e0cc549797f4138ec1f (patch)
treef585c3ebc16d7feaeef87b3563dbb4f6656a8450
parent97cc968a133247e729ed1d189d35ef2b7b53b3d4 (diff)
downloaddexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar.gz
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar.bz2
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar.lz
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar.xz
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.tar.zst
dexon-solidity-64ddb176bb71498f3a129e0cc549797f4138ec1f.zip
Test for accessing outer inline assembly scope.
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp27
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp35
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)