From 5844955dd8fa925a9ced19b324391d9e0b7c0824 Mon Sep 17 00:00:00 2001 From: r0qs <457348+r0qs@users.noreply.github.com> Date: Sat, 20 Dec 2025 17:30:56 -0300 Subject: [PATCH] evmasm: Support struct array copying from memory/calldata to storage in evmasm pipeline --- libsolidity/codegen/ArrayUtils.cpp | 12 ------------ .../array_of_struct_calldata_to_storage.sol | 6 +++--- .../array_of_struct_memory_to_storage.sol | 4 ++-- ...ts_containing_arrays_calldata_to_storage.sol | 6 +++--- ...ucts_containing_arrays_memory_to_storage.sol | 6 +++--- ..._calldata_struct_array_to_storage_legacy.sol | 16 ---------------- ...py_memory_struct_array_to_storage_legacy.sol | 17 ----------------- 7 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 test/libsolidity/syntaxTests/array/copy_calldata_struct_array_to_storage_legacy.sol delete mode 100644 test/libsolidity/syntaxTests/array/copy_memory_struct_array_to_storage_legacy.sol diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index 841161fa91b6..0261feefe1a5 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -71,18 +71,6 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons "Copying nested calldata dynamic arrays to storage is not implemented in the old code generator." ); } - else - { - // TODO: This limitation can now be removed since we use Yul utility functions that handle non-value types correctly. - // The old inline assembly implementation couldn't handle copying arrays of non-value types from memory or calldata to storage, - // but the Yul functions support them. We keep this check temporarily for backward compatibility. - bool fromMemoryOrCalldata = _sourceType.location() == DataLocation::Memory || _sourceType.location() == DataLocation::CallData; - solUnimplementedAssert( - _sourceType.baseType()->isValueType() || !fromMemoryOrCalldata, - "Copying of type " + _sourceType.toString(false) + " to storage is not supported in legacy (only supported by the IR pipeline). " + - "Hint: try compiling with `--via-ir` (CLI) or the equivalent `viaIR: true` (Standard JSON)." - ); - } if (haveSourceLengthOnStack) { diff --git a/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol index e4b3d14fd76b..a48b45e0681d 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_struct_calldata_to_storage.sol @@ -1,4 +1,4 @@ -pragma abicoder v2; +pragma abicoder v2; contract C { struct S { @@ -13,8 +13,8 @@ contract C { return (s[2].a, s[1].b, s[0].c); } } -// ==== -// compileViaYul: true // ---- // f((uint128,uint64,uint128)[]): 0x20, 3, 0, 0, 12, 0, 11, 0, 10, 0, 0 -> 10, 11, 12 // gas irOptimized: 120751 +// gas legacy: 126254 +// gas legacyOptimized: 121447 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_struct_memory_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_struct_memory_to_storage.sol index 5b3fe1f7016f..5a5511ab95e0 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_struct_memory_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_struct_memory_to_storage.sol @@ -15,8 +15,8 @@ contract C { return (s[2].a, s[1].b, s[0].c); } } -// ==== -// compileViaYul: true // ---- // f() -> 10, 11, 12 // gas irOptimized: 118796 +// gas legacy: 124947 +// gas legacyOptimized: 119164 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_calldata_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_calldata_to_storage.sol index acc968389229..0ecd31947484 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_calldata_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_calldata_to_storage.sol @@ -1,4 +1,4 @@ -pragma abicoder v2; +pragma abicoder v2; contract C { struct S { @@ -19,8 +19,8 @@ contract C { return (s[1].a.length, s[1].a[0]); } } -// ==== -// compileViaYul: true // ---- // f((uint256[])[]): 0x20, 3, 0x60, 0x60, 0x60, 0x20, 3, 1, 2, 3 -> 3, 1 // gas irOptimized: 327461 +// gas legacy: 332254 +// gas legacyOptimized: 327667 diff --git a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol index 355c268f2514..0d7a85996a03 100644 --- a/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol +++ b/test/libsolidity/semanticTests/array/copying/array_of_structs_containing_arrays_memory_to_storage.sol @@ -1,4 +1,4 @@ -pragma abicoder v2; +pragma abicoder v2; contract C { struct S { @@ -22,8 +22,8 @@ contract C { return (s[1].b.length, s[1].c.length, s[1].b[2], s[1].c[0]); } } -// ==== -// compileViaYul: true // ---- // f() -> 3, 3, 3, 1 // gas irOptimized: 181928 +// gas legacy: 190874 +// gas legacyOptimized: 183072 diff --git a/test/libsolidity/syntaxTests/array/copy_calldata_struct_array_to_storage_legacy.sol b/test/libsolidity/syntaxTests/array/copy_calldata_struct_array_to_storage_legacy.sol deleted file mode 100644 index 8c45b5b9f520..000000000000 --- a/test/libsolidity/syntaxTests/array/copy_calldata_struct_array_to_storage_legacy.sol +++ /dev/null @@ -1,16 +0,0 @@ -contract C { - struct S { - uint256 a; - uint256 b; - } - - S[] storageArray; - - function copyFromCalldata(S[] calldata calldataArray) public { - storageArray = calldataArray; - } -} -// ==== -// compileViaYul: false -// ---- -// UnimplementedFeatureError 1834: (0-208): Copying of type struct C.S calldata[] calldata to storage is not supported in legacy (only supported by the IR pipeline). Hint: try compiling with `--via-ir` (CLI) or the equivalent `viaIR: true` (Standard JSON). diff --git a/test/libsolidity/syntaxTests/array/copy_memory_struct_array_to_storage_legacy.sol b/test/libsolidity/syntaxTests/array/copy_memory_struct_array_to_storage_legacy.sol deleted file mode 100644 index 86e8bf1f6344..000000000000 --- a/test/libsolidity/syntaxTests/array/copy_memory_struct_array_to_storage_legacy.sol +++ /dev/null @@ -1,17 +0,0 @@ -contract C { - struct S { - uint256 a; - uint256 b; - } - - S[] storageArray; - - function copyFromMemory() public { - S[] memory memArray = new S[](3); - storageArray = memArray; - } -} -// ==== -// compileViaYul: false -// ---- -// UnimplementedFeatureError 1834: (0-217): Copying of type struct C.S memory[] memory to storage is not supported in legacy (only supported by the IR pipeline). Hint: try compiling with `--via-ir` (CLI) or the equivalent `viaIR: true` (Standard JSON).