Skip to content

Commit 0d1f552

Browse files
committed
wip
1 parent 0d84691 commit 0d1f552

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

libsolidity/codegen/ArrayUtils.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,15 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
289289
// stack: target_ref target_data_end source_data_pos target_data_pos_updated source_data_end
290290
_context << Instruction::POP << Instruction::SWAP1 << Instruction::POP;
291291
// stack: target_ref target_data_end target_data_pos_updated
292-
if (targetBaseType->storageBytes() < 32)
293-
utils.clearStorageLoop(TypeProvider::uint256(), /* _canOverflow */ false);
292+
if (_targetType.isDynamicallySized())
293+
ArrayUtils(_context).clearDynamicArray(_targetType);
294294
else
295-
utils.clearStorageLoop(targetBaseType, /* _canOverflow */ false);
295+
{
296+
if (targetBaseType->storageBytes() < 32)
297+
utils.clearStorageLoop(TypeProvider::uint256(), /* _canOverflow */ true);
298+
else
299+
utils.clearStorageLoop(targetBaseType, /* _canOverflow */ true);
300+
}
296301
_context << Instruction::POP;
297302
}
298303
);
@@ -590,7 +595,6 @@ void ArrayUtils::clearArray(ArrayType const& _typeIn) const
590595
ArrayUtils(_context).convertLengthToSize(_type);
591596
_context << Instruction::ADD << Instruction::SWAP1;
592597
if (_type.baseType()->storageBytes() < 32)
593-
// wraps around cleaning for static arrays
594598
ArrayUtils(_context).clearStorageLoop(TypeProvider::uint256(), !_type.isDynamicallySized());
595599
else
596600
ArrayUtils(_context).clearStorageLoop(_type.baseType(), !_type.isDynamicallySized());

libsolidity/codegen/YulUtilFunctions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ std::string YulUtilFunctions::cleanUpStorageArrayEndFunction(ArrayType const& _t
14311431
)")
14321432
("convertToSize", arrayConvertLengthToSize(_type))
14331433
("dataPosition", arrayDataAreaFunction(_type))
1434-
("clearStorageRange", clearStorageRangeFunction(*_type.baseType(), /* _canOverflow */ false))
1434+
("clearStorageRange", clearStorageRangeFunction(*_type.baseType(), !_type.isDynamicallySized()))
14351435
("packed", _type.baseType()->storageBytes() <= 16)
14361436
("itemsPerSlot", std::to_string(32 / _type.baseType()->storageBytes()))
14371437
("storageBytes", std::to_string(_type.baseType()->storageBytes()))

test/libsolidity/semanticTests/array/push/array_push_struct.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ contract c {
2222
// test() -> 2, 3, 4, 5
2323
// gas irOptimized: 135329
2424
// gas legacy: 147437
25-
// gas legacyOptimized: 146429
25+
// gas legacyOptimized: 148715

test/libsolidity/semanticTests/types/mapping/copy_from_mapping_to_mapping.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ contract C {
3131
// f() -> 0x20, 7, 8, 9, 0xa0, 13, 2, 0x40, 0xa0, 2, 3, 4, 2, 3, 4
3232
// gas irOptimized: 197102
3333
// gas legacy: 199887
34-
// gas legacyOptimized: 196845
34+
// gas legacyOptimized: 203694

0 commit comments

Comments
 (0)