From ae8508b0c4fd75dbe5bcae002daa8dcf311d5e14 Mon Sep 17 00:00:00 2001 From: r0qs <457348+r0qs@users.noreply.github.com> Date: Fri, 19 Dec 2025 23:14:27 -0300 Subject: [PATCH] evmasm: Remove unused return value from `clearStorageLoop()` --- libsolidity/codegen/ArrayUtils.cpp | 16 +++++++--------- libsolidity/codegen/ArrayUtils.h | 2 +- .../array/copying/array_copy_including_array.sol | 8 ++++---- .../array/delete/delete_storage_array_packed.sol | 4 ++-- .../semanticTests/array/fixed_array_cleanup.sol | 4 ++-- .../array/pop/array_pop_array_transition.sol | 4 ++-- .../storage_boundary_delete_overflow_bug.sol | 4 ++-- ...storage_boundary_struct_array_mixed_types.sol | 4 ++-- .../storage_boundary_struct_array_multislot.sol | 4 ++-- .../structs/struct_delete_storage_with_array.sol | 8 ++++---- .../userDefinedValueType/calldata.sol | 8 ++++---- 11 files changed, 32 insertions(+), 34 deletions(-) diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 841161fa91b6..80ee9553c0ae 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -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, ""); } @@ -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 @@ -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 @@ -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 @@ -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, ""); } ); } diff --git a/libsolidity/codegen/ArrayUtils.h b/libsolidity/codegen/ArrayUtils.h index a62df8a7b2ab..a5eda28f5275 100644 --- a/libsolidity/codegen/ArrayUtils.h +++ b/libsolidity/codegen/ArrayUtils.h @@ -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. diff --git a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol index ba50c7300f65..5f1dae910d6b 100644 --- a/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol +++ b/test/libsolidity/semanticTests/array/copying/array_copy_including_array.sol @@ -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 diff --git a/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol b/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol index 23b0466e7530..cf416c16d192 100644 --- a/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol +++ b/test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol @@ -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 diff --git a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol index af0ec6b7faf0..86484ecdef09 100644 --- a/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol +++ b/test/libsolidity/semanticTests/array/fixed_array_cleanup.sol @@ -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 diff --git a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol index 3b96397166ea..ed4e9b87737c 100644 --- a/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol +++ b/test/libsolidity/semanticTests/array/pop/array_pop_array_transition.sol @@ -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 diff --git a/test/libsolidity/semanticTests/storage/storage_boundary_delete_overflow_bug.sol b/test/libsolidity/semanticTests/storage/storage_boundary_delete_overflow_bug.sol index 3ffb7774710a..09aae988e511 100644 --- a/test/libsolidity/semanticTests/storage/storage_boundary_delete_overflow_bug.sol +++ b/test/libsolidity/semanticTests/storage/storage_boundary_delete_overflow_bug.sol @@ -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 diff --git a/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_mixed_types.sol b/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_mixed_types.sol index 213dee1dae23..444f86286453 100644 --- a/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_mixed_types.sol +++ b/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_mixed_types.sol @@ -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 diff --git a/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_multislot.sol b/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_multislot.sol index 55e36cd08e06..05ad53cf0bfa 100644 --- a/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_multislot.sol +++ b/test/libsolidity/semanticTests/storage/storage_boundary_struct_array_multislot.sol @@ -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 diff --git a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol index cd49ea27ad0e..7ae78437e408 100644 --- a/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol +++ b/test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol @@ -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 diff --git a/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol b/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol index 03c6e11bcc3c..63f1ff1dd18e 100644 --- a/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol +++ b/test/libsolidity/semanticTests/userDefinedValueType/calldata.sol @@ -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