From 1a9e66f4b0bbf79e25d03b7cbc6784a6f820f869 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 9 Jun 2022 16:03:46 +0200 Subject: [PATCH] Tests --- ...nup_during_multi_element_per_slot_copy.sol | 22 ++++++++ .../array/function_type_array_to_storage.sol | 56 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/libsolidity/semanticTests/array/cleanup_during_multi_element_per_slot_copy.sol create mode 100644 test/libsolidity/semanticTests/array/function_type_array_to_storage.sol diff --git a/test/libsolidity/semanticTests/array/cleanup_during_multi_element_per_slot_copy.sol b/test/libsolidity/semanticTests/array/cleanup_during_multi_element_per_slot_copy.sol new file mode 100644 index 000000000..c3cc74c29 --- /dev/null +++ b/test/libsolidity/semanticTests/array/cleanup_during_multi_element_per_slot_copy.sol @@ -0,0 +1,22 @@ +contract C { + uint32[] s; + constructor() + { + s.push(); + s.push(); + } + function f() external returns (uint) + { + (s[1], s) = (4, [0]); + s = [0]; + s.push(); + return s[1]; + // used to return 4 via IR. + } +} +// ---- +// constructor() +// gas irOptimized: 237351 +// gas legacy: 221315 +// gas legacyOptimized: 185247 +// f() -> 0 diff --git a/test/libsolidity/semanticTests/array/function_type_array_to_storage.sol b/test/libsolidity/semanticTests/array/function_type_array_to_storage.sol new file mode 100644 index 000000000..94feaba3d --- /dev/null +++ b/test/libsolidity/semanticTests/array/function_type_array_to_storage.sol @@ -0,0 +1,56 @@ +contract C { + string log; + function() external[] fs; + function() external[] gs; + + function a() external { + log = string.concat(log, "[a called]"); + } + function b() external { + log = string.concat(log, "[b called]"); + } + + function f(function() external[] calldata x) external { + fs = x; + } + function g(function() external[] memory x) public { + fs = x; + } + function test() external returns (string memory) { + log = ""; + function() external[] memory x = new function() external[](2); + x[0] = this.a; + x[1] = this.b; + this.f(x); + fs[0](); + fs[1](); + return log; + } + function test2() external returns (string memory) { + log = ""; + function() external[] memory x = new function() external[](2); + x[0] = this.b; + x[1] = this.a; + g(x); + fs[0](); + fs[1](); + return log; + } + function test3() external returns (string memory) { + log = ""; + gs = fs; + gs[0](); + gs[1](); + return log; + } +} +// ---- +// test() -> 0x20, 0x14, "[a called][b called]" +// gas irOptimized: 116724 +// gas legacy: 120707 +// gas legacyOptimized: 119241 +// test2() -> 0x20, 0x14, "[b called][a called]" +// test3() -> 0x20, 0x14, "[b called][a called]" +// gas irOptimized: 103304 +// gas legacy: 104648 +// gas legacyOptimized: 104075