diff options
-rw-r--r-- | libsolidity/codegen/LValue.cpp | 12 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 31 |
2 files changed, 33 insertions, 10 deletions
diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 66449fc4..2ec7f800 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -177,6 +177,7 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const m_context << Instruction::POP << Instruction::SLOAD; else { + bool cleaned = false; m_context << Instruction::SWAP1 << Instruction::SLOAD << Instruction::SWAP1 << u256(0x100) << Instruction::EXP << Instruction::SWAP1 << Instruction::DIV; @@ -184,18 +185,27 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const // implementation should be very similar to the integer case. solUnimplemented("Not yet implemented - FixedPointType."); if (m_dataType->category() == Type::Category::FixedBytes) + { m_context << (u256(0x1) << (256 - 8 * m_dataType->storageBytes())) << Instruction::MUL; + cleaned = true; + } else if ( m_dataType->category() == Type::Category::Integer && dynamic_cast<IntegerType const&>(*m_dataType).isSigned() ) + { m_context << u256(m_dataType->storageBytes() - 1) << Instruction::SIGNEXTEND; + cleaned = true; + } else if (FunctionType const* fun = dynamic_cast<decltype(fun)>(m_dataType)) { if (fun->location() == FunctionType::Location::External) + { CompilerUtils(m_context).splitExternalFunctionType(false); + cleaned = true; + } } - else + if (!cleaned) { solAssert(m_dataType->sizeOnStack() == 1, ""); m_context << ((u256(0x1) << (8 * m_dataType->storageBytes())) - 1) << Instruction::AND; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a1236803..8f9edadf 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -7878,19 +7878,20 @@ BOOST_AUTO_TEST_CASE(mapping_of_functions) stages[msg.sender] = stage0; } - function f() { + function f() returns (uint) { stages[msg.sender](); + return 7; } } )"; compileAndRun(sourceCode, 0, "Flow"); - BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(false)); - BOOST_CHECK(callContractFunction("f()") == encodeArgs()); - BOOST_CHECK(callContractFunction("f()") == encodeArgs()); - BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(false)); - BOOST_CHECK(callContractFunction("f()") == encodeArgs()); - BOOST_CHECK(callContractFunction("checkSuccess()") == encodeArgs(true)); + BOOST_CHECK(callContractFunction("success()") == encodeArgs(false)); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7))); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7))); + BOOST_CHECK(callContractFunction("success()") == encodeArgs(false)); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(7))); + BOOST_CHECK(callContractFunction("success()") == encodeArgs(true)); } BOOST_AUTO_TEST_CASE(packed_functions) @@ -7900,12 +7901,16 @@ BOOST_AUTO_TEST_CASE(packed_functions) // these should take the same slot function() returns (uint) a; function() external returns (uint) b; + function() external returns (uint) c; + function() returns (uint) d; uint8 public x; function set() { x = 2; + d = g; + c = this.h; + b = this.h; a = g; - b = h; } function t1() returns (uint) { return a(); @@ -7913,6 +7918,12 @@ BOOST_AUTO_TEST_CASE(packed_functions) function t2() returns (uint) { return b(); } + function t3() returns (uint) { + return a(); + } + function t4() returns (uint) { + return b(); + } function g() returns (uint) { return 7; } @@ -7926,6 +7937,8 @@ BOOST_AUTO_TEST_CASE(packed_functions) BOOST_CHECK(callContractFunction("set()") == encodeArgs()); BOOST_CHECK(callContractFunction("t1()") == encodeArgs(u256(7))); BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(8))); + BOOST_CHECK(callContractFunction("t3()") == encodeArgs(u256(7))); + BOOST_CHECK(callContractFunction("t4()") == encodeArgs(u256(8))); BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(2))); } @@ -7939,7 +7952,7 @@ BOOST_AUTO_TEST_CASE(function_memory_array) function d(uint x) returns (uint) { return x + 5; } function e(uint x) returns (uint) { return x + 8; } function test(uint x, uint i) returns (uint) { - function(uint) internal returns (uint)[] arr = + function(uint) internal returns (uint)[] memory arr = new function(uint) internal returns (uint)[](10); arr[0] = a; arr[1] = b; |