aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-11-29 07:59:01 +0800
committerchriseth <c@ethdev.com>2015-11-29 08:03:39 +0800
commit6796afc2f8b441803a2c03f28271a1421935e536 (patch)
treed41d0990f034d218d53fea10486cc493be008ca2
parentc806b9bcdb26fe031da94b8cdb270cb3c75b8af9 (diff)
downloaddexon-solidity-6796afc2f8b441803a2c03f28271a1421935e536.tar.gz
dexon-solidity-6796afc2f8b441803a2c03f28271a1421935e536.tar.zst
dexon-solidity-6796afc2f8b441803a2c03f28271a1421935e536.zip
Bugfix for constructor unpacking with fixed-size arrays.
-rw-r--r--libsolidity/codegen/Compiler.cpp18
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp17
2 files changed, 30 insertions, 5 deletions
diff --git a/libsolidity/codegen/Compiler.cpp b/libsolidity/codegen/Compiler.cpp
index f1d95980..18803b71 100644
--- a/libsolidity/codegen/Compiler.cpp
+++ b/libsolidity/codegen/Compiler.cpp
@@ -305,11 +305,19 @@ void Compiler::appendCalldataUnpacker(TypePointers const& _typeParameters, bool
// @todo If base type is an array or struct, it is still calldata-style encoded, so
// we would have to convert it like below.
solAssert(arrayType.location() == DataLocation::Memory, "");
- // compute data pointer
- m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
- m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
- m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
- m_context << u256(0x20) << eth::Instruction::ADD;
+ if (arrayType.isDynamicallySized())
+ {
+ // compute data pointer
+ m_context << eth::Instruction::DUP1 << eth::Instruction::MLOAD;
+ m_context << eth::Instruction::DUP3 << eth::Instruction::ADD;
+ m_context << eth::Instruction::SWAP2 << eth::Instruction::SWAP1;
+ m_context << u256(0x20) << eth::Instruction::ADD;
+ }
+ else
+ {
+ m_context << eth::Instruction::DUP1;
+ m_context << u256(arrayType.calldataEncodedSize(true)) << eth::Instruction::ADD;
+ }
}
else
{
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0b356145..5782e6c8 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -4671,6 +4671,23 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors)
);
}
+BOOST_AUTO_TEST_CASE(fixed_arrays_in_constructors)
+{
+ char const* sourceCode = R"(
+ contract Creator {
+ uint public r;
+ address public ch;
+ function Creator(address[3] s, uint x) {
+ r = x;
+ ch = s[2];
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Creator", encodeArgs(u256(1), u256(2), u256(3), u256(4)));
+ BOOST_REQUIRE(callContractFunction("r()") == encodeArgs(u256(4)));
+ BOOST_REQUIRE(callContractFunction("ch()") == encodeArgs(u256(3)));
+}
+
BOOST_AUTO_TEST_CASE(arrays_from_and_to_storage)
{
char const* sourceCode = R"(