From a27b063c10be48f303b499a90bf988c3ce5bc4ee Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 19 May 2022 20:50:41 +0200 Subject: [PATCH] Test for buggy behaviour. --- .../byte_array_to_storage_cleanup.sol | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol diff --git a/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol b/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol new file mode 100644 index 000000000..ed9b234ff --- /dev/null +++ b/test/libsolidity/semanticTests/byte_array_to_storage_cleanup.sol @@ -0,0 +1,36 @@ +contract C { + event ev0(uint[] i0, uint); + bytes public s2; + function h() external returns (bytes memory) { + uint[] memory x = new uint[](2); + emit ev0(x, 0x21); + bytes memory m = new bytes(63); + s2 = m; + s2.push(); + return s2; + } + function g() external returns (bytes memory) { + bytes memory m = new bytes(63); + assembly { + mstore8(add(m, add(32, 63)), 0x42) + } + s2 = m; + s2.push(); + return s2; + } + function f(bytes calldata c) external returns (bytes memory) { + s2 = c; + s2.push(); + return s2; + } +} +// ==== +// compileViaYul: false +// ---- +// constructor() -> +// gas legacy: 616124 +// gas legacyOptimized: 450817 +// h() -> 0x20, 0x40, 0x00, 2 +// ~ emit ev0(uint256[],uint256): 0x40, 0x21, 0x02, 0x00, 0x00 +// g() -> 0x20, 0x40, 0, 0x42 +// f(bytes): 0x20, 33, 0, -1 -> 0x20, 0x22, 0, 0xffff000000000000000000000000000000000000000000000000000000000000