mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Properly cleanup after copying dynamic-array to storage for packed types
This commit is contained in:
committed by
hrkrshnn
parent
87e1934bee
commit
1bdbc10110
@@ -633,8 +633,8 @@ BOOST_AUTO_TEST_CASE(optimise_multi_stores)
|
||||
)";
|
||||
compileBothVersions(sourceCode);
|
||||
compareVersions("f()");
|
||||
BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::SSTORE), 9);
|
||||
BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 8);
|
||||
BOOST_CHECK_EQUAL(numInstructions(m_nonOptimizedBytecode, Instruction::SSTORE), 8);
|
||||
BOOST_CHECK_EQUAL(numInstructions(m_optimizedBytecode, Instruction::SSTORE), 7);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(optimise_constant_to_codecopy)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Test to see if cleanup is performed properly during array copying
|
||||
contract C {
|
||||
uint128[] x;
|
||||
function f() public returns(bool) {
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
uint128[] memory y = new uint128[](1);
|
||||
y[0] = 23;
|
||||
x = y;
|
||||
assembly { sstore(x.slot, 4) }
|
||||
|
||||
assert(x[0] == 23);
|
||||
assert(x[1] == 0);
|
||||
|
||||
assert(x[2] == 0);
|
||||
// Issue 9832: the cleanup was only performed for the first packed type leaving the rest of
|
||||
// the slot dirty.
|
||||
assert(x[3] == 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> true
|
||||
@@ -0,0 +1,48 @@
|
||||
// Issue 9832: Test to see if cleanup is performed properly after array copying
|
||||
contract C {
|
||||
uint40[] x;
|
||||
function f() public returns(bool) {
|
||||
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
x.push(42); x.push(42); x.push(42); x.push(42);
|
||||
|
||||
uint40[] memory y = new uint40[](1);
|
||||
y[0] = 23;
|
||||
x = y;
|
||||
|
||||
assembly { sstore(x.slot, 20) }
|
||||
|
||||
assert(x[0] == 23);
|
||||
assert(x[1] == 0);
|
||||
assert(x[2] == 0);
|
||||
assert(x[3] == 0);
|
||||
|
||||
assert(x[4] == 0);
|
||||
assert(x[5] == 0);
|
||||
assert(x[6] == 0);
|
||||
assert(x[7] == 0);
|
||||
|
||||
assert(x[8] == 0);
|
||||
assert(x[9] == 0);
|
||||
assert(x[10] == 0);
|
||||
assert(x[11] == 0);
|
||||
|
||||
assert(x[12] == 0);
|
||||
assert(x[13] == 0);
|
||||
assert(x[14] == 0);
|
||||
assert(x[15] == 0);
|
||||
|
||||
assert(x[16] == 0);
|
||||
assert(x[17] == 0);
|
||||
assert(x[18] == 0);
|
||||
assert(x[19] == 0);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> true
|
||||
Reference in New Issue
Block a user