From a0c80c2bdb39e86b8a189a2fdad8584d501b12cb Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Mon, 18 Jan 2021 12:34:15 +0100 Subject: [PATCH 1/2] [Sol->Yul] Enabling copying_bytes_multiassign test via ir. --- .../codegen/ir/IRGeneratorForStatements.cpp | 9 ++++---- test/libsolidity/SolidityEndToEndTest.cpp | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 7ad962473..b28034f83 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -449,12 +449,11 @@ bool IRGeneratorForStatements::visit(Assignment const& _assignment) writeToLValue(*m_currentLValue, value); - if ( - m_currentLValue->type.category() != Type::Category::Struct && - m_currentLValue->type.category() != Type::Category::Array && - *_assignment.annotation().type != *TypeProvider::emptyTuple() - ) + if (dynamic_cast(&m_currentLValue->type)) + define(_assignment, readFromLValue(*m_currentLValue)); + else if (*_assignment.annotation().type != *TypeProvider::emptyTuple()) define(_assignment, value); + m_currentLValue.reset(); return false; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index ddc34888c..99911e9a3 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2419,15 +2419,18 @@ BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) bytes savedData2; } )"; - compileAndRun(sourceCode, 0, "sender"); - ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); - ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); - ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); - ABI_CHECK(callContractFunction("forward(bool)", false), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(16)); - ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN() + compileAndRun(sourceCode, 0, "sender"); + ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); + ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); + ABI_CHECK(callContractFunction("forward(bool)", false), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(16)); + ABI_CHECK(callContractFunction("forward(bool)", true), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); + ); } BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data) From d738a5219c4740086dd605f6e8f9f52ff571e986 Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Mon, 18 Jan 2021 12:49:10 +0100 Subject: [PATCH 2/2] Activating more end to end tests via ir. --- test/libsolidity/SolidityEndToEndTest.cpp | 57 +++++++++++++---------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 99911e9a3..6d56b37b1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2317,11 +2317,14 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory) } } )"; - compileAndRun(sourceCode); - bytes calldata1 = FixedHash<4>(util::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); - sendMessage(calldata1, false); - BOOST_CHECK(m_transactionSuccessful); - BOOST_CHECK(m_output == encodeArgs(util::keccak256(bytes{'a', 'b', 'c'} + calldata1))); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN(); + compileAndRun(sourceCode); + bytes calldata1 = FixedHash<4>(util::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12); + sendMessage(calldata1, false); + BOOST_CHECK(m_transactionSuccessful); + BOOST_CHECK(m_output == encodeArgs(util::keccak256(bytes{'a', 'b', 'c'} + calldata1))); + ); } BOOST_AUTO_TEST_CASE(call_forward_bytes) @@ -2342,15 +2345,18 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes) bytes savedData; } )"; - compileAndRun(sourceCode, 0, "sender"); - ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); - ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); - ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); - ABI_CHECK(callContractFunction("clear()"), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); - ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); - ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN(); + compileAndRun(sourceCode, 0, "sender"); + ABI_CHECK(callContractFunction("recv(uint256)", 7), bytes()); + ABI_CHECK(callContractFunction("val()"), encodeArgs(0)); + ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); + ABI_CHECK(callContractFunction("clear()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(8)); + ABI_CHECK(callContractFunction("forward()"), encodeArgs(true)); + ABI_CHECK(callContractFunction("val()"), encodeArgs(0x80)); + ); } BOOST_AUTO_TEST_CASE(call_forward_bytes_length) @@ -2383,18 +2389,21 @@ BOOST_AUTO_TEST_CASE(call_forward_bytes_length) } } )"; - compileAndRun(sourceCode, 0, "sender"); + ALSO_VIA_YUL( + DISABLE_EWASM_TESTRUN(); + compileAndRun(sourceCode, 0, "sender"); - // No additional data, just function selector - ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); - ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); - ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); + // No additional data, just function selector + ABI_CHECK(callContractFunction("viaCalldata()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaMemory()"), encodeArgs(4)); + ABI_CHECK(callContractFunction("viaStorage()"), encodeArgs(4)); - // Some additional unpadded data - bytes unpadded = asBytes(string("abc")); - ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); - ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); + // Some additional unpadded data + bytes unpadded = asBytes(string("abc")); + ABI_CHECK(callContractFunctionNoEncoding("viaCalldata()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaMemory()", unpadded), encodeArgs(7)); + ABI_CHECK(callContractFunctionNoEncoding("viaStorage()", unpadded), encodeArgs(7)); + ); } BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)