Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions libsolidity/codegen/ArrayUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ void ArrayUtils::clearArray(ArrayType const& _typeIn) const
ArrayUtils(_context).clearStorageLoop(TypeProvider::uint256());
else
ArrayUtils(_context).clearStorageLoop(_type.baseType());
_context << Instruction::POP;
}
solAssert(_context.stackHeight() == stackHeightStart - 2, "");
}
Expand All @@ -425,9 +424,10 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
// stack: ref old_length
m_context << Instruction::DUP1 << u256(31) << Instruction::LT;
evmasm::AssemblyItem longByteArray = m_context.appendConditionalJump();
m_context << Instruction::POP;
// Short byte array: no data slots to clear, just pop and exit
m_context << Instruction::POP << Instruction::POP;
m_context.appendJumpTo(endTag);
m_context.adjustStackOffset(1); // needed because of jump
m_context.adjustStackOffset(2); // the longByteArray path has 2 more items on stack
m_context << longByteArray;
}
// stack: ref old_length
Expand All @@ -444,7 +444,6 @@ void ArrayUtils::clearDynamicArray(ArrayType const& _type) const
clearStorageLoop(_type.baseType());
// cleanup
m_context << endTag;
m_context << Instruction::POP;
}

void ArrayUtils::incrementDynamicArraySize(ArrayType const& _type) const
Expand Down Expand Up @@ -585,13 +584,13 @@ void ArrayUtils::clearStorageLoop(Type const* _type) const
m_context.callLowLevelFunction(
"$clearStorageLoop_" + _type->identifier(),
2,
1,
0,
[_type](CompilerContext& _context)
{
unsigned stackHeightStart = _context.stackHeight();
if (_type->category() == Type::Category::Mapping)
{
_context << Instruction::POP;
_context << Instruction::POP << Instruction::POP;
return;
}
// stack: start_pos slot_count
Expand All @@ -618,9 +617,8 @@ void ArrayUtils::clearStorageLoop(Type const* _type) const
// cleanup
_context << zeroLoopEnd;
// stack: start_pos slot_count i
_context << Instruction::POP << Instruction::POP;
// stack: start_pos
solAssert(_context.stackHeight() == stackHeightStart - 1, "");
_context << Instruction::POP << Instruction::POP << Instruction::POP;
solAssert(_context.stackHeight() == stackHeightStart - 2, "");
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ArrayUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ArrayUtils
void popStorageArrayElement(ArrayType const& _type) const;
/// Appends a loop that clears a sequence of storage slots of the given type.
/// Stack pre: start_ref slot_count
/// Stack post: start_ref
/// Stack post:
void clearStorageLoop(Type const* _type) const;
/// Converts length to size (number of storage slots or calldata/memory bytes).
/// if @a _pad then add padding to multiples of 32 bytes for calldata/memory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ contract c {
// ----
// test() -> 0x02000202
// gas irOptimized: 4560468
// gas legacy: 4536566
// gas legacyOptimized: 4456759
// gas legacy: 4536539
// gas legacyOptimized: 4456732
// storageEmpty -> 1
// clear() -> 0, 0
// gas irOptimized: 4488719
// gas legacy: 4407780
// gas legacyOptimized: 4385089
// gas legacy: 4407759
// gas legacyOptimized: 4385068
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ contract C {
// ----
// f() -> 0, 0, 0
// gas irOptimized: 88028
// gas legacy: 88799
// gas legacyOptimized: 87706
// gas legacy: 88796
// gas legacyOptimized: 87704
4 changes: 2 additions & 2 deletions test/libsolidity/semanticTests/array/fixed_array_cleanup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ contract c {
// storageEmpty -> 0
// clear() ->
// gas irOptimized: 97800
// gas legacy: 97947
// gas legacyOptimized: 97882
// gas legacy: 97944
// gas legacyOptimized: 97880
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ contract c {
// ----
// test() -> 1, 2, 3
// gas irOptimized: 1828383
// gas legacy: 1841995
// gas legacyOptimized: 1821687
// gas legacy: 1841877
// gas legacyOptimized: 1821569
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ contract C {
// gas legacyOptimized: 598016
// clearArray()
// gas irOptimized: 580378
// gas legacy: 582976
// gas legacyOptimized: 581290
// gas legacy: 582973
// gas legacyOptimized: 581299
// x() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// gas irOptimized: 604108
// gas legacy: 644983
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ contract C {
// gas legacyOptimized: 112505
// deleteBoundaryArray()
// gas irOptimized: 177968
// gas legacy: 180997
// gas legacyOptimized: 178175
// gas legacy: 180995
// gas legacyOptimized: 178182
// canaryValue() -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// boundaryArray() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// gas irOptimized: 113169
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ contract C {
// destArray() -> 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
// deleteBoundaryArray()
// gas irOptimized: 137824
// gas legacy: 137973
// gas legacyOptimized: 137743
// gas legacy: 137971
// gas legacyOptimized: 137750
// canaryValue() -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
// boundaryArray() -> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// destArray() -> 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ contract C {
// ----
// f() ->
// gas irOptimized: 113388
// gas legacy: 113588
// gas legacyOptimized: 113104
// gas legacy: 113583
// gas legacyOptimized: 113119
// g() ->
// gas irOptimized: 118768
// gas legacy: 118766
// gas legacyOptimized: 118188
// gas legacy: 118761
// gas legacyOptimized: 118203
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ contract C {
// ----
// test_f() -> true
// gas irOptimized: 122114
// gas legacy: 126162
// gas legacyOptimized: 122757
// gas legacy: 126159
// gas legacyOptimized: 122742
// test_g() -> true
// gas irOptimized: 106248
// gas legacy: 111824
// gas legacyOptimized: 106606
// gas legacy: 111821
// gas legacyOptimized: 106591
// addresses(uint256): 0 -> 0x18
// addresses(uint256): 1 -> 0x19
// addresses(uint256): 3 -> 0x1b
Expand Down