From cd60ade4727f9a8c5f99cf34ef1a949fb4815686 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 11 Dec 2020 16:09:09 +0000 Subject: [PATCH 1/5] Improve some Yul object and command line tests to avoid using pop() which can be optimized out --- .../strict_asm_optimizer_steps/input.yul | 2 +- .../strict_asm_optimizer_steps/output | 17 +- test/libyul/objectCompiler/metadata.yul | 50 ++- .../libyul/objectCompiler/subObjectAccess.yul | 286 ++++++++++++++---- 4 files changed, 279 insertions(+), 76 deletions(-) diff --git a/test/cmdlineTests/strict_asm_optimizer_steps/input.yul b/test/cmdlineTests/strict_asm_optimizer_steps/input.yul index b1c756df3..18214a31d 100644 --- a/test/cmdlineTests/strict_asm_optimizer_steps/input.yul +++ b/test/cmdlineTests/strict_asm_optimizer_steps/input.yul @@ -14,7 +14,7 @@ object "C_6" { let selector := shift_right_224_unsigned(calldataload(0)) pop(selector) } - pop(iszero(calldatasize())) + sstore(0, iszero(calldatasize())) revert(0, 0) } diff --git a/test/cmdlineTests/strict_asm_optimizer_steps/output b/test/cmdlineTests/strict_asm_optimizer_steps/output index 369be348c..7341e15e9 100644 --- a/test/cmdlineTests/strict_asm_optimizer_steps/output +++ b/test/cmdlineTests/strict_asm_optimizer_steps/output @@ -16,6 +16,7 @@ object "C_6" { { mstore(64, 128) pop(iszero(lt(calldatasize(), 4))) + sstore(0, iszero(calldatasize())) revert(0, 0) } } @@ -24,7 +25,7 @@ object "C_6" { Binary representation: -60806040523415600f5760006000fd5b6010601d60003960106000f3fe608060405260043610155060006000fd +60806040523415600f5760006000fd5b6015601d60003960156000f3fe6080604052600436101550361560005560006000fd Text representation: /* "strict_asm_optimizer_steps/input.yul":45:48 */ @@ -79,10 +80,18 @@ sub_0: assembly { iszero /* "strict_asm_optimizer_steps/input.yul":319:321 */ pop - /* "strict_asm_optimizer_steps/input.yul":570:571 */ + /* "strict_asm_optimizer_steps/input.yul":533:547 */ + calldatasize + /* "strict_asm_optimizer_steps/input.yul":526:548 */ + iszero + /* "strict_asm_optimizer_steps/input.yul":523:524 */ 0x00 - /* "strict_asm_optimizer_steps/input.yul":567:568 */ + /* "strict_asm_optimizer_steps/input.yul":516:549 */ + sstore + /* "strict_asm_optimizer_steps/input.yul":576:577 */ 0x00 - /* "strict_asm_optimizer_steps/input.yul":560:572 */ + /* "strict_asm_optimizer_steps/input.yul":573:574 */ + 0x00 + /* "strict_asm_optimizer_steps/input.yul":566:578 */ revert } diff --git a/test/libyul/objectCompiler/metadata.yul b/test/libyul/objectCompiler/metadata.yul index 8f3b087a3..9facd54e4 100644 --- a/test/libyul/objectCompiler/metadata.yul +++ b/test/libyul/objectCompiler/metadata.yul @@ -1,11 +1,16 @@ object "A" { code { - pop(datasize("x")) - pop(datasize("C")) + let x := datasize("x") + let c := datasize("C") + sstore(0, x) + sstore(32, c) } object "B" { - code { pop(dataoffset("other")) } + code { + let o := dataoffset("other") + sstore(0, o) + } data ".metadata" "M1" data "other" "Hello, World2!" } @@ -16,17 +21,38 @@ object "A" { } // ---- // Assembly: -// /* "source":26:44 */ -// pop(0x0e) -// /* "source":49:67 */ -// pop(0x03) +// 0x0e +// /* "source":26:48 */ +// 0x03 +// /* "source":90:91 */ +// dup2 +// /* "source":87:88 */ +// 0x00 +// /* "source":80:92 */ +// sstore +// /* "source":108:109 */ +// dup1 +// /* "source":104:106 */ +// 0x20 +// /* "source":97:110 */ +// sstore +// /* "source":20:114 */ +// pop +// pop // stop // data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221 // data_e1629b9dda060bb30c7908346f6af189c16773fa148d3366701fbaa35d54f3c8 414243 // // sub_0: assembly { -// /* "source":99:123 */ -// pop(data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336) +// data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 +// /* "source":193:194 */ +// dup1 +// /* "source":190:191 */ +// 0x00 +// /* "source":183:195 */ +// sstore +// /* "source":140:201 */ +// pop // stop // data_211450822d7f8c345093893187e7e1fbebc4ec67af72601920194be14104e336 48656c6c6f2c20576f726c643221 // @@ -34,6 +60,6 @@ object "A" { // } // // auxdata: 0x4d32 -// Bytecode: 600e50600350fe4d32 -// Opcodes: PUSH1 0xE POP PUSH1 0x3 POP INVALID 0x4D ORIGIN -// SourceMappings: 26:18:0:-:0;;49; +// Bytecode: 600e600381600055806020555050fe4d32 +// Opcodes: PUSH1 0xE PUSH1 0x3 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE POP POP INVALID 0x4D ORIGIN +// SourceMappings: :::-:0;26:22:0;90:1;87;80:12;108:1;104:2;97:13;20:94; diff --git a/test/libyul/objectCompiler/subObjectAccess.yul b/test/libyul/objectCompiler/subObjectAccess.yul index 4fddc2483..627d802ba 100644 --- a/test/libyul/objectCompiler/subObjectAccess.yul +++ b/test/libyul/objectCompiler/subObjectAccess.yul @@ -1,32 +1,56 @@ object "A" { code { - pop(dataoffset("A")) - pop(datasize("A")) - pop(dataoffset("B")) - pop(datasize("B")) - pop(dataoffset("B.C")) - pop(datasize("B.C")) - pop(dataoffset("B.E")) - pop(datasize("B.E")) - pop(dataoffset("B.C.D")) - pop(datasize("B.C.D")) + let a_o := dataoffset("A") + let a_s := datasize("A") + let b_o := dataoffset("B") + let b_s := datasize("B") + let bc_o := dataoffset("B.C") + let bc_s := datasize("B.C") + let be_o := dataoffset("B.E") + let be_s := datasize("B.E") + let bcd_o := dataoffset("B.C.D") + let bcd_s := datasize("B.C.D") + + sstore(0, a_o) + sstore(32, a_s) + sstore(64, b_o) + sstore(96, b_s) + sstore(128, bc_o) + sstore(160, bc_s) + sstore(192, be_o) + sstore(224, be_s) + sstore(256, bcd_o) + sstore(288, bcd_s) + return(0, 320) } data "data1" "Hello, World!" object "B" { code { - pop(dataoffset("C")) - pop(datasize("C")) - pop(dataoffset("E")) - pop(datasize("E")) - pop(dataoffset("C.D")) - pop(datasize("C.D")) + let c_o := dataoffset("C") + let c_s := datasize("C") + let e_o := dataoffset("E") + let e_s := datasize("E") + let cd_o := dataoffset("C.D") + let cd_s := datasize("C.D") + + sstore(0, c_o) + sstore(32, c_s) + sstore(64, e_o) + sstore(96, e_s) + sstore(128, cd_o) + sstore(160, cd_s) + return(0, 192) } object "C" { code { - pop(dataoffset("D")) - pop(datasize("D")) + let d_o := dataoffset("D") + let d_s := datasize("D") + + sstore(0, d_o) + sstore(32, d_s) + return(0, 64) } object "D" { code { @@ -43,62 +67,206 @@ object "A" { } // ---- // Assembly: -// /* "source":26:46 */ -// pop(0x00) -// /* "source":51:69 */ -// pop(bytecodeSize) -// /* "source":74:94 */ -// pop(dataOffset(sub_0)) -// /* "source":99:117 */ -// pop(dataSize(sub_0)) -// /* "source":122:144 */ -// pop(dataOffset(sub_0.sub_0)) -// /* "source":149:169 */ -// pop(dataSize(sub_0.sub_0)) -// /* "source":174:196 */ -// pop(dataOffset(sub_0.sub_1)) -// /* "source":201:221 */ -// pop(dataSize(sub_0.sub_1)) -// /* "source":226:250 */ -// pop(dataOffset(sub_0.sub_0.sub_0)) -// /* "source":255:277 */ -// pop(dataSize(sub_0.sub_0.sub_0)) +// 0x00 +// /* "source":26:52 */ +// bytecodeSize +// /* "source":57:81 */ +// dataOffset(sub_0) +// /* "source":86:112 */ +// dataSize(sub_0) +// /* "source":117:141 */ +// dataOffset(sub_0.sub_0) +// /* "source":146:175 */ +// dataSize(sub_0.sub_0) +// /* "source":180:207 */ +// dataOffset(sub_0.sub_1) +// /* "source":212:241 */ +// dataSize(sub_0.sub_1) +// /* "source":246:273 */ +// dataOffset(sub_0.sub_0.sub_0) +// /* "source":278:310 */ +// dataSize(sub_0.sub_0.sub_0) +// /* "source":361:364 */ +// dup10 +// /* "source":358:359 */ +// 0x00 +// /* "source":351:365 */ +// sstore +// /* "source":381:384 */ +// dup9 +// /* "source":377:379 */ +// 0x20 +// /* "source":370:385 */ +// sstore +// /* "source":401:404 */ +// dup8 +// /* "source":397:399 */ +// 0x40 +// /* "source":390:405 */ +// sstore +// /* "source":421:424 */ +// dup7 +// /* "source":417:419 */ +// 0x60 +// /* "source":410:425 */ +// sstore +// /* "source":442:446 */ +// dup6 +// /* "source":437:440 */ +// 0x80 +// /* "source":430:447 */ +// sstore +// /* "source":464:468 */ +// dup5 +// /* "source":459:462 */ +// 0xa0 +// /* "source":452:469 */ +// sstore +// /* "source":486:490 */ +// dup4 +// /* "source":481:484 */ +// 0xc0 +// /* "source":474:491 */ +// sstore +// /* "source":508:512 */ +// dup3 +// /* "source":503:506 */ +// 0xe0 +// /* "source":496:513 */ +// sstore +// /* "source":530:535 */ +// dup2 +// /* "source":525:528 */ +// 0x0100 +// /* "source":518:536 */ +// sstore +// /* "source":553:558 */ +// dup1 +// /* "source":548:551 */ +// 0x0120 +// /* "source":541:559 */ +// sstore +// /* "source":574:577 */ +// 0x0140 +// /* "source":571:572 */ +// 0x00 +// /* "source":564:578 */ +// return +// /* "source":20:582 */ +// pop +// pop +// pop +// pop +// pop +// pop +// pop +// pop +// pop +// pop // stop // data_acaf3289d7b601cbd114fb36c4d29c85bbfd5e133f14cb355c3fd8d99367964f 48656c6c6f2c20576f726c6421 // // sub_0: assembly { -// /* "source":347:367 */ -// pop(dataOffset(sub_0)) -// /* "source":374:392 */ -// pop(dataSize(sub_0)) -// /* "source":399:419 */ -// pop(dataOffset(sub_1)) -// /* "source":426:444 */ -// pop(dataSize(sub_1)) -// /* "source":451:473 */ -// pop(dataOffset(sub_0.sub_0)) -// /* "source":480:500 */ -// pop(dataSize(sub_0.sub_0)) +// dataOffset(sub_0) +// /* "source":648:674 */ +// dataSize(sub_0) +// /* "source":681:705 */ +// dataOffset(sub_1) +// /* "source":712:738 */ +// dataSize(sub_1) +// /* "source":745:769 */ +// dataOffset(sub_0.sub_0) +// /* "source":776:805 */ +// dataSize(sub_0.sub_0) +// /* "source":857:860 */ +// dup6 +// /* "source":854:855 */ +// 0x00 +// /* "source":847:861 */ +// sstore +// /* "source":879:882 */ +// dup5 +// /* "source":875:877 */ +// 0x20 +// /* "source":868:883 */ +// sstore +// /* "source":901:904 */ +// dup4 +// /* "source":897:899 */ +// 0x40 +// /* "source":890:905 */ +// sstore +// /* "source":923:926 */ +// dup3 +// /* "source":919:921 */ +// 0x60 +// /* "source":912:927 */ +// sstore +// /* "source":946:950 */ +// dup2 +// /* "source":941:944 */ +// 0x80 +// /* "source":934:951 */ +// sstore +// /* "source":970:974 */ +// dup1 +// /* "source":965:968 */ +// 0xa0 +// /* "source":958:975 */ +// sstore +// /* "source":992:995 */ +// 0xc0 +// /* "source":989:990 */ +// 0x00 +// /* "source":982:996 */ +// return +// /* "source":640:1002 */ +// pop +// pop +// pop +// pop +// pop +// pop // stop // // sub_0: assembly { -// /* "source":545:565 */ -// pop(dataOffset(sub_0)) -// /* "source":574:592 */ -// pop(dataSize(sub_0)) +// dataOffset(sub_0) +// /* "source":1041:1067 */ +// dataSize(sub_0) +// /* "source":1120:1123 */ +// dup2 +// /* "source":1117:1118 */ +// 0x00 +// /* "source":1110:1124 */ +// sstore +// /* "source":1144:1147 */ +// dup1 +// /* "source":1140:1142 */ +// 0x20 +// /* "source":1133:1148 */ +// sstore +// /* "source":1167:1169 */ +// 0x40 +// /* "source":1164:1165 */ +// 0x00 +// /* "source":1157:1170 */ +// return +// /* "source":1031:1178 */ +// pop +// pop // stop // // sub_0: assembly { -// /* "source":645:654 */ +// /* "source":1223:1232 */ // invalid // } // } // // sub_1: assembly { -// /* "source":717:726 */ +// /* "source":1295:1304 */ // invalid // } // } -// Bytecode: 600050604650601f50601d50603e50600850603d50600150603c50600150fe601350600850601b50600150601c50600150fe600750600150fefefefefefe600750600150fefe -// Opcodes: PUSH1 0x0 POP PUSH1 0x46 POP PUSH1 0x1F POP PUSH1 0x1D POP PUSH1 0x3E POP PUSH1 0x8 POP PUSH1 0x3D POP PUSH1 0x1 POP PUSH1 0x3C POP PUSH1 0x1 POP INVALID PUSH1 0x13 POP PUSH1 0x8 POP PUSH1 0x1B POP PUSH1 0x1 POP PUSH1 0x1C POP PUSH1 0x1 POP INVALID PUSH1 0x7 POP PUSH1 0x1 POP INVALID INVALID INVALID INVALID INVALID INVALID PUSH1 0x7 POP PUSH1 0x1 POP INVALID INVALID -// SourceMappings: 26:20:0:-:0;;51:18;;74:20;;99:18;;122:22;;149:20;;174:22;;201:20;;226:24;;255:22; +// Bytecode: 600060ad604f604760986015609760016096600189600055886020558760405586606055856080558460a0558360c0558260e055816101005580610120556101406000f350505050505050505050fe60306015604560016046600185600055846020558360405582606055816080558060a05560c06000f3505050505050fe60146001816000558060205560406000f35050fefefefefefe60146001816000558060205560406000f35050fefe +// Opcodes: PUSH1 0x0 PUSH1 0xAD PUSH1 0x4F PUSH1 0x47 PUSH1 0x98 PUSH1 0x15 PUSH1 0x97 PUSH1 0x1 PUSH1 0x96 PUSH1 0x1 DUP10 PUSH1 0x0 SSTORE DUP9 PUSH1 0x20 SSTORE DUP8 PUSH1 0x40 SSTORE DUP7 PUSH1 0x60 SSTORE DUP6 PUSH1 0x80 SSTORE DUP5 PUSH1 0xA0 SSTORE DUP4 PUSH1 0xC0 SSTORE DUP3 PUSH1 0xE0 SSTORE DUP2 PUSH2 0x100 SSTORE DUP1 PUSH2 0x120 SSTORE PUSH2 0x140 PUSH1 0x0 RETURN POP POP POP POP POP POP POP POP POP POP INVALID PUSH1 0x30 PUSH1 0x15 PUSH1 0x45 PUSH1 0x1 PUSH1 0x46 PUSH1 0x1 DUP6 PUSH1 0x0 SSTORE DUP5 PUSH1 0x20 SSTORE DUP4 PUSH1 0x40 SSTORE DUP3 PUSH1 0x60 SSTORE DUP2 PUSH1 0x80 SSTORE DUP1 PUSH1 0xA0 SSTORE PUSH1 0xC0 PUSH1 0x0 RETURN POP POP POP POP POP POP INVALID PUSH1 0x14 PUSH1 0x1 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE PUSH1 0x40 PUSH1 0x0 RETURN POP POP INVALID INVALID INVALID INVALID INVALID INVALID PUSH1 0x14 PUSH1 0x1 DUP2 PUSH1 0x0 SSTORE DUP1 PUSH1 0x20 SSTORE PUSH1 0x40 PUSH1 0x0 RETURN POP POP INVALID INVALID +// SourceMappings: :::-:0;26:26:0;57:24;86:26;117:24;146:29;180:27;212:29;246:27;278:32;361:3;358:1;351:14;381:3;377:2;370:15;401:3;397:2;390:15;421:3;417:2;410:15;442:4;437:3;430:17;464:4;459:3;452:17;486:4;481:3;474:17;508:4;503:3;496:17;530:5;525:3;518:18;553:5;548:3;541:18;574:3;571:1;564:14;20:562;;;;;;;;; From 703a73f949c1fb3d73d0b36a92446b2a8afd15cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 27 Apr 2021 00:05:46 +0200 Subject: [PATCH 2/5] EVMCodeTransformTest: Disable all non-stack optimizations --- test/libyul/EVMCodeTransformTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libyul/EVMCodeTransformTest.cpp b/test/libyul/EVMCodeTransformTest.cpp index 58a0c2795..eea7e0914 100644 --- a/test/libyul/EVMCodeTransformTest.cpp +++ b/test/libyul/EVMCodeTransformTest.cpp @@ -44,7 +44,7 @@ EVMCodeTransformTest::EVMCodeTransformTest(string const& _filename): TestCase::TestResult EVMCodeTransformTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted) { - solidity::frontend::OptimiserSettings settings = solidity::frontend::OptimiserSettings::full(); + solidity::frontend::OptimiserSettings settings = solidity::frontend::OptimiserSettings::none(); settings.runYulOptimiser = false; settings.optimizeStackAllocation = m_stackOpt; AssemblyStack stack(EVMVersion{}, AssemblyStack::Language::StrictAssembly, settings); From 9d08b5001f6db3b57434002c1ca94dfc30e51b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 22 Apr 2021 16:08:32 +0200 Subject: [PATCH 3/5] Add sstore to linker tests to prevent the address from being optimized out --- .../linking_standard_yul/input.json | 2 +- .../input.json | 2 +- .../input.json | 2 +- .../linking_strict_assembly/input.yul | 1 + .../linking_strict_assembly/output | 11 +++++++++-- .../input.yul | 1 + .../input.yul | 1 + .../output | 15 ++++++++++++--- .../input.yul | 2 ++ .../output | 18 ++++++++++++++++-- .../input.yul | 2 ++ .../output | 18 ++++++++++++++++-- .../input.yul | 2 ++ .../output | 18 ++++++++++++++++-- test/libsolidity/StandardCompiler.cpp | 8 ++++---- 15 files changed, 85 insertions(+), 18 deletions(-) diff --git a/test/cmdlineTests/linking_standard_yul/input.json b/test/cmdlineTests/linking_standard_yul/input.json index 3825a1b12..80fb2d6ad 100644 --- a/test/cmdlineTests/linking_standard_yul/input.json +++ b/test/cmdlineTests/linking_standard_yul/input.json @@ -2,7 +2,7 @@ "language": "Yul", "sources": { "A": { - "content": "object \"a\" { code { let addr := linkersymbol(\"contract/test.sol:L\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"contract/test.sol:L\") sstore(0, addr) } }" } }, "settings": { diff --git a/test/cmdlineTests/linking_standard_yul_quote_in_file_name/input.json b/test/cmdlineTests/linking_standard_yul_quote_in_file_name/input.json index 24fe9d61a..2a0c59a81 100644 --- a/test/cmdlineTests/linking_standard_yul_quote_in_file_name/input.json +++ b/test/cmdlineTests/linking_standard_yul_quote_in_file_name/input.json @@ -2,7 +2,7 @@ "language": "Yul", "sources": { "A": { - "content": "object \"a\" { code { let addr := linkersymbol(\"contract/test\\\".sol:L\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"contract/test\\\".sol:L\") sstore(0, addr) } }" } }, "settings": { diff --git a/test/cmdlineTests/linking_standard_yul_unresolved_references/input.json b/test/cmdlineTests/linking_standard_yul_unresolved_references/input.json index 39f0f7c3a..220ac9ce1 100644 --- a/test/cmdlineTests/linking_standard_yul_unresolved_references/input.json +++ b/test/cmdlineTests/linking_standard_yul_unresolved_references/input.json @@ -2,7 +2,7 @@ "language": "Yul", "sources": { "A": { - "content": "object \"a\" { code { let addr1 := linkersymbol(\"contract/test.sol:L1\") let addr2 := linkersymbol(\"contract/test.sol:L2\") } }" + "content": "object \"a\" { code { let addr1 := linkersymbol(\"contract/test.sol:L1\") let addr2 := linkersymbol(\"contract/test.sol:L2\") sstore(0, addr1) sstore(1, addr2) } }" } }, "settings": { diff --git a/test/cmdlineTests/linking_strict_assembly/input.yul b/test/cmdlineTests/linking_strict_assembly/input.yul index be2052771..ec3f1e077 100644 --- a/test/cmdlineTests/linking_strict_assembly/input.yul +++ b/test/cmdlineTests/linking_strict_assembly/input.yul @@ -1,5 +1,6 @@ object "a" { code { let addr := linkersymbol("contract/test.sol:L") + sstore(0, addr) } } diff --git a/test/cmdlineTests/linking_strict_assembly/output b/test/cmdlineTests/linking_strict_assembly/output index 23b2826f1..8a58b94e4 100644 --- a/test/cmdlineTests/linking_strict_assembly/output +++ b/test/cmdlineTests/linking_strict_assembly/output @@ -5,14 +5,21 @@ Pretty printed source: object "a" { code { let addr := linkersymbol("contract/test.sol:L") + sstore(0, addr) } } Binary representation: -73123456789012345678901234567890123456789050 +7312345678901234567890123456789012345678908060005550 Text representation: linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612") - /* "linking_strict_assembly/input.yul":22:85 */ + /* "linking_strict_assembly/input.yul":98:102 */ + dup1 + /* "linking_strict_assembly/input.yul":95:96 */ + 0x00 + /* "linking_strict_assembly/input.yul":88:103 */ + sstore + /* "linking_strict_assembly/input.yul":22:109 */ pop diff --git a/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/input.yul b/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/input.yul index c4dda1ceb..d0b6077be 100644 --- a/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/input.yul +++ b/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/input.yul @@ -1,5 +1,6 @@ object "a" { code { let addr := linkersymbol("library.sol:L") + sstore(0, addr) } } diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul index b4dbc3cbc..fcfab5bcf 100644 --- a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul +++ b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/input.yul @@ -1,5 +1,6 @@ object "a" { code { let addr := linkersymbol("L") + sstore(0, addr) } } diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output index c7a9339b6..871bacf2e 100644 --- a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output +++ b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output @@ -3,14 +3,23 @@ Pretty printed source: object "a" { - code { let addr := linkersymbol("L") } + code { + let addr := linkersymbol("L") + sstore(0, addr) + } } Binary representation: -73123456789012345678901234567890123456789050 +7312345678901234567890123456789012345678908060005550 Text representation: linkerSymbol("8aa64f937099b65a4febc243a5ae0f2d6416bb9e473c30dd29c1ee498fb7c5a8") - /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":22:67 */ + /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":80:84 */ + dup1 + /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":77:78 */ + 0x00 + /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":70:85 */ + sstore + /* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":22:91 */ pop diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/input.yul b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/input.yul index acb612857..1d4cfa367 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/input.yul +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/input.yul @@ -2,5 +2,7 @@ object "a" { code { let addr1 := linkersymbol("library1.sol:L") let addr2 := linkersymbol("library2.sol:L") + sstore(0, addr1) + sstore(1, addr2) } } diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/output b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/output index 80696c594..eb74885ee 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/output +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/output @@ -6,17 +6,31 @@ object "a" { code { let addr1 := linkersymbol("library1.sol:L") let addr2 := linkersymbol("library2.sol:L") + sstore(0, addr1) + sstore(1, addr2) } } Binary representation: -7311111111111111111111111111111111111111117322222222222222222222222222222222222222225050 +73111111111111111111111111111111111111111173222222222222222222222222222222222222222281600055806001555050 Text representation: linkerSymbol("f3ffc10c396a7cc41ae954b050792839d20947bf73497d30c49a9fda1ea477ec") /* "linking_strict_assembly_same_library_name_different_files/input.yul":32:75 */ linkerSymbol("c3523432985587641d17c68161d2f700c57aaf4ed21cda4f25d76193c831f97f") - /* "linking_strict_assembly_same_library_name_different_files/input.yul":22:133 */ + /* "linking_strict_assembly_same_library_name_different_files/input.yul":146:151 */ + dup2 + /* "linking_strict_assembly_same_library_name_different_files/input.yul":143:144 */ + 0x00 + /* "linking_strict_assembly_same_library_name_different_files/input.yul":136:152 */ + sstore + /* "linking_strict_assembly_same_library_name_different_files/input.yul":171:176 */ + dup1 + /* "linking_strict_assembly_same_library_name_different_files/input.yul":168:169 */ + 0x01 + /* "linking_strict_assembly_same_library_name_different_files/input.yul":161:177 */ + sstore + /* "linking_strict_assembly_same_library_name_different_files/input.yul":22:183 */ pop pop diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul index acb612857..1d4cfa367 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul @@ -2,5 +2,7 @@ object "a" { code { let addr1 := linkersymbol("library1.sol:L") let addr2 := linkersymbol("library2.sol:L") + sstore(0, addr1) + sstore(1, addr2) } } diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output index 150355ba1..b5a44af48 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output @@ -6,17 +6,31 @@ object "a" { code { let addr1 := linkersymbol("library1.sol:L") let addr2 := linkersymbol("library2.sol:L") + sstore(0, addr1) + sstore(1, addr2) } } Binary representation: -73123456789012345678901234567890123456789073__$c3523432985587641d17c68161d2f700c5$__5050 +73123456789012345678901234567890123456789073__$c3523432985587641d17c68161d2f700c5$__81600055806001555050 Text representation: linkerSymbol("f3ffc10c396a7cc41ae954b050792839d20947bf73497d30c49a9fda1ea477ec") /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":32:75 */ linkerSymbol("c3523432985587641d17c68161d2f700c57aaf4ed21cda4f25d76193c831f97f") - /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":22:133 */ + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":146:151 */ + dup2 + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":143:144 */ + 0x00 + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":136:152 */ + sstore + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":171:176 */ + dup1 + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":168:169 */ + 0x01 + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":161:177 */ + sstore + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":22:183 */ pop pop diff --git a/test/cmdlineTests/linking_strict_assembly_unresolved_references/input.yul b/test/cmdlineTests/linking_strict_assembly_unresolved_references/input.yul index b64cc4bae..fc5d05a8b 100644 --- a/test/cmdlineTests/linking_strict_assembly_unresolved_references/input.yul +++ b/test/cmdlineTests/linking_strict_assembly_unresolved_references/input.yul @@ -2,5 +2,7 @@ object "a" { code { let addr1 := linkersymbol("contract/test.sol:L1") let addr2 := linkersymbol("contract/test.sol:L2") + sstore(0, addr1) + sstore(1, addr2) } } diff --git a/test/cmdlineTests/linking_strict_assembly_unresolved_references/output b/test/cmdlineTests/linking_strict_assembly_unresolved_references/output index accbaa09e..f927894ce 100644 --- a/test/cmdlineTests/linking_strict_assembly_unresolved_references/output +++ b/test/cmdlineTests/linking_strict_assembly_unresolved_references/output @@ -6,17 +6,31 @@ object "a" { code { let addr1 := linkersymbol("contract/test.sol:L1") let addr2 := linkersymbol("contract/test.sol:L2") + sstore(0, addr1) + sstore(1, addr2) } } Binary representation: -73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__5050 +73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__81600055806001555050 Text representation: linkerSymbol("05b0326038374a21e0895480a58bda0768cdcc04c8d18f154362d1ca5223d245") /* "linking_strict_assembly_unresolved_references/input.yul":32:81 */ linkerSymbol("fb58009a6b1ecea3b9d99bedd645df4ec308f17bc0087e5f39d078f77f809177") - /* "linking_strict_assembly_unresolved_references/input.yul":22:145 */ + /* "linking_strict_assembly_unresolved_references/input.yul":158:163 */ + dup2 + /* "linking_strict_assembly_unresolved_references/input.yul":155:156 */ + 0x00 + /* "linking_strict_assembly_unresolved_references/input.yul":148:164 */ + sstore + /* "linking_strict_assembly_unresolved_references/input.yul":183:188 */ + dup1 + /* "linking_strict_assembly_unresolved_references/input.yul":180:181 */ + 0x01 + /* "linking_strict_assembly_unresolved_references/input.yul":173:189 */ + sstore + /* "linking_strict_assembly_unresolved_references/input.yul":22:195 */ pop pop diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 6f72026bb..0dce223ba 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -924,7 +924,7 @@ BOOST_AUTO_TEST_CASE(linking_yul) }, "sources": { "fileA": { - "content": "object \"a\" { code { let addr := linkersymbol(\"fileB:L\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"fileB:L\") sstore(0, addr) } }" } } } @@ -956,7 +956,7 @@ BOOST_AUTO_TEST_CASE(linking_yul_empty_link_reference) }, "sources": { "fileA": { - "content": "object \"a\" { code { let addr := linkersymbol(\"\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"\") sstore(0, addr) } }" } } } @@ -988,7 +988,7 @@ BOOST_AUTO_TEST_CASE(linking_yul_no_filename_in_link_reference) }, "sources": { "fileA": { - "content": "object \"a\" { code { let addr := linkersymbol(\"L\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"L\") sstore(0, addr) } }" } } } @@ -1020,7 +1020,7 @@ BOOST_AUTO_TEST_CASE(linking_yul_same_library_name_different_files) }, "sources": { "fileA": { - "content": "object \"a\" { code { let addr := linkersymbol(\"fileC:L\") } }" + "content": "object \"a\" { code { let addr := linkersymbol(\"fileC:L\") sstore(0, addr) } }" } } } From 753f359157c697547469944dfd819b17b236aed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 1 Jul 2021 14:35:12 +0200 Subject: [PATCH 4/5] Replace stack optimization command-line test with Standard JSON ones - It's not possible to run optimizer with only stack optimization enabled on the CLI. --- .../input.json} | 26 ++ .../standard_yul_stack_opt/output.json | 304 ++++++++++++++++++ .../input.json} | 27 ++ .../output.json | 9 + test/cmdlineTests/yul_stack_opt/args | 1 - test/cmdlineTests/yul_stack_opt/err | 1 - test/cmdlineTests/yul_stack_opt/output | 205 ------------ test/cmdlineTests/yul_stack_opt_disabled/args | 1 - test/cmdlineTests/yul_stack_opt_disabled/err | 5 - test/cmdlineTests/yul_stack_opt_disabled/exit | 1 - .../yul_stack_opt_disabled/output | 30 -- 11 files changed, 366 insertions(+), 244 deletions(-) rename test/cmdlineTests/{yul_stack_opt/input.yul => standard_yul_stack_opt/input.json} (70%) create mode 100644 test/cmdlineTests/standard_yul_stack_opt/output.json rename test/cmdlineTests/{yul_stack_opt_disabled/input.yul => standard_yul_stack_opt_disabled/input.json} (65%) create mode 100644 test/cmdlineTests/standard_yul_stack_opt_disabled/output.json delete mode 100644 test/cmdlineTests/yul_stack_opt/args delete mode 100644 test/cmdlineTests/yul_stack_opt/err delete mode 100644 test/cmdlineTests/yul_stack_opt/output delete mode 100644 test/cmdlineTests/yul_stack_opt_disabled/args delete mode 100644 test/cmdlineTests/yul_stack_opt_disabled/err delete mode 100644 test/cmdlineTests/yul_stack_opt_disabled/exit delete mode 100644 test/cmdlineTests/yul_stack_opt_disabled/output diff --git a/test/cmdlineTests/yul_stack_opt/input.yul b/test/cmdlineTests/standard_yul_stack_opt/input.json similarity index 70% rename from test/cmdlineTests/yul_stack_opt/input.yul rename to test/cmdlineTests/standard_yul_stack_opt/input.json index d60620ecf..b9e5141ac 100644 --- a/test/cmdlineTests/yul_stack_opt/input.yul +++ b/test/cmdlineTests/standard_yul_stack_opt/input.json @@ -1,4 +1,10 @@ { + "language": "Yul", + "sources": + { + "A": + { + "content": "{ function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, n3, o3, p3 { let a := 1 @@ -36,4 +42,24 @@ let a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1 := fun() let a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2 := fun() sstore(a1, a2) +}" + } + }, + "settings": + { + "optimizer": { + "enabled": false, + "details": { + "yul": true, + "yulDetails": { + "stackAllocation": true, + "optimizerSteps": "c" + } + } + }, + "outputSelection": + { + "*": {"*": ["evm.assembly"]} + } + } } diff --git a/test/cmdlineTests/standard_yul_stack_opt/output.json b/test/cmdlineTests/standard_yul_stack_opt/output.json new file mode 100644 index 000000000..1e50cec28 --- /dev/null +++ b/test/cmdlineTests/standard_yul_stack_opt/output.json @@ -0,0 +1,304 @@ +{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":645:650 */ + tag_1 + tag_2 + jump\t// in +tag_1: + /* \"A\":575:650 */ + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + /* \"A\":722:727 */ + tag_3 + tag_2 + jump\t// in +tag_3: + /* \"A\":652:727 */ + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + pop + /* \"A\":740:742 */ + dup1 + /* \"A\":736:738 */ + dup3 + /* \"A\":729:743 */ + sstore + pop + pop + /* \"A\":3:573 */ + jump(tag_4) +tag_2: + /* \"A\":98:99 */ + 0x01 + 0x01 + /* \"A\":129:141 */ + sstore + /* \"A\":98:99 */ + 0x01 + 0x01 + 0x01 + /* \"A\":151:160 */ + add + /* \"A\":144:164 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":181:182 */ + 0x02 + /* \"A\":98:99 */ + 0x01 + /* \"A\":174:183 */ + add + /* \"A\":167:187 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":204:205 */ + 0x03 + /* \"A\":98:99 */ + 0x01 + /* \"A\":197:206 */ + add + /* \"A\":190:210 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":227:228 */ + 0x04 + /* \"A\":98:99 */ + 0x01 + /* \"A\":220:229 */ + add + /* \"A\":213:233 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":250:251 */ + 0x05 + /* \"A\":98:99 */ + 0x01 + /* \"A\":243:252 */ + add + /* \"A\":236:256 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":273:274 */ + 0x06 + /* \"A\":98:99 */ + 0x01 + /* \"A\":266:275 */ + add + /* \"A\":259:279 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":296:297 */ + 0x07 + /* \"A\":98:99 */ + 0x01 + /* \"A\":289:298 */ + add + /* \"A\":282:302 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":319:320 */ + 0x08 + /* \"A\":98:99 */ + 0x01 + /* \"A\":312:321 */ + add + /* \"A\":305:325 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":342:343 */ + 0x09 + /* \"A\":98:99 */ + 0x01 + /* \"A\":335:344 */ + add + /* \"A\":328:348 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":365:367 */ + 0x0a + /* \"A\":98:99 */ + 0x01 + /* \"A\":358:368 */ + add + /* \"A\":351:372 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":389:391 */ + 0x0b + /* \"A\":98:99 */ + 0x01 + /* \"A\":382:392 */ + add + /* \"A\":375:396 */ + sstore + /* \"A\":98:99 */ + 0x01 + /* \"A\":413:415 */ + 0x0c + /* \"A\":98:99 */ + 0x01 + /* \"A\":406:416 */ + add + /* \"A\":399:420 */ + sstore + /* \"A\":21:23 */ + 0x00 + /* \"A\":25:27 */ + 0x00 + /* \"A\":29:31 */ + 0x00 + /* \"A\":33:35 */ + 0x00 + /* \"A\":37:39 */ + 0x00 + /* \"A\":41:43 */ + 0x00 + /* \"A\":45:47 */ + 0x00 + /* \"A\":49:51 */ + 0x00 + /* \"A\":53:55 */ + 0x00 + /* \"A\":57:59 */ + 0x00 + /* \"A\":61:63 */ + 0x00 + /* \"A\":65:67 */ + 0x00 + /* \"A\":69:71 */ + 0x00 + /* \"A\":73:75 */ + 0x00 + /* \"A\":77:79 */ + 0x00 + /* \"A\":81:83 */ + 0x00 + /* \"A\":98:99 */ + 0x01 + /* \"A\":423:430 */ + swap16 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":433:440 */ + swap15 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":443:450 */ + swap14 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":453:460 */ + swap13 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":463:470 */ + swap12 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":473:480 */ + swap11 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":483:490 */ + swap10 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":493:500 */ + swap9 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":503:510 */ + swap8 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":513:520 */ + swap7 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":523:530 */ + swap6 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":533:540 */ + swap5 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":543:550 */ + swap4 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":553:560 */ + swap2 + pop + /* \"A\":98:99 */ + dup16 + /* \"A\":563:570 */ + swap1 + pop + /* \"A\":85:573 */ +tag_5: + swap1 + swap2 + swap3 + swap4 + swap5 + swap6 + swap7 + swap8 + swap9 + swap10 + swap11 + swap12 + swap13 + swap14 + swap15 + swap16 + jump\t// out +tag_4: +"}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]} diff --git a/test/cmdlineTests/yul_stack_opt_disabled/input.yul b/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json similarity index 65% rename from test/cmdlineTests/yul_stack_opt_disabled/input.yul rename to test/cmdlineTests/standard_yul_stack_opt_disabled/input.json index 772a6d4df..ad1057aea 100644 --- a/test/cmdlineTests/yul_stack_opt_disabled/input.yul +++ b/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json @@ -1,4 +1,10 @@ { + "language": "Yul", + "sources": + { + "A": + { + "content": "{ function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, n3, o3, p3 { let a := 1 @@ -22,3 +28,24 @@ let a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2 := fun() sstore(a1, a2) } +" + } + }, + "settings": + { + "optimizer": { + "enabled": false, + "details": { + "yul": true, + "yulDetails": { + "stackAllocation": false, + "optimizerSteps": "c" + } + } + }, + "outputSelection": + { + "*": {"*": ["evm.assembly"]} + } + } +} diff --git a/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json b/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json new file mode 100644 index 000000000..9529dddc5 --- /dev/null +++ b/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json @@ -0,0 +1,9 @@ +{"errors":[{"component":"general","formattedMessage":"Internal exception in StandardCompiler::compile: /solidity/libyul/backends/evm/EVMObjectCompiler.cpp(70): Throw in function void solidity::yul::EVMObjectCompiler::run(solidity::yul::Object&, bool) +Dynamic exception type: boost::wrapexcept +std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. +[solidity::util::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. +","message":"Internal exception in StandardCompiler::compile: /solidity/libyul/backends/evm/EVMObjectCompiler.cpp(70): Throw in function void solidity::yul::EVMObjectCompiler::run(solidity::yul::Object&, bool) +Dynamic exception type: boost::wrapexcept +std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. +[solidity::util::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. +","severity":"error","type":"InternalCompilerError"}]} diff --git a/test/cmdlineTests/yul_stack_opt/args b/test/cmdlineTests/yul_stack_opt/args deleted file mode 100644 index 20fe41eb5..000000000 --- a/test/cmdlineTests/yul_stack_opt/args +++ /dev/null @@ -1 +0,0 @@ ---strict-assembly --optimize diff --git a/test/cmdlineTests/yul_stack_opt/err b/test/cmdlineTests/yul_stack_opt/err deleted file mode 100644 index 014a1178f..000000000 --- a/test/cmdlineTests/yul_stack_opt/err +++ /dev/null @@ -1 +0,0 @@ -Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/yul_stack_opt/output b/test/cmdlineTests/yul_stack_opt/output deleted file mode 100644 index 7c0e8ca66..000000000 --- a/test/cmdlineTests/yul_stack_opt/output +++ /dev/null @@ -1,205 +0,0 @@ - -======= yul_stack_opt/input.yul (EVM) ======= - -Pretty printed source: -object "object" { - code { - { - let _1 := 1 - sstore(_1, _1) - sstore(2, _1) - sstore(3, _1) - sstore(4, _1) - sstore(5, _1) - sstore(6, _1) - sstore(7, _1) - sstore(8, _1) - sstore(9, _1) - sstore(10, _1) - sstore(11, _1) - sstore(12, _1) - sstore(13, _1) - sstore(_1, _1) - sstore(2, _1) - sstore(3, _1) - sstore(4, _1) - sstore(5, _1) - sstore(6, _1) - sstore(7, _1) - sstore(8, _1) - sstore(9, _1) - sstore(10, _1) - sstore(11, _1) - sstore(12, _1) - sstore(13, _1) - sstore(_1, _1) - } - } -} - - -Binary representation: -6001808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d5580815550 - -Text representation: - /* "yul_stack_opt/input.yul":98:99 */ - 0x01 - dup1 - dup2 - /* "yul_stack_opt/input.yul":129:141 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":151:160 */ - 0x02 - /* "yul_stack_opt/input.yul":144:164 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":174:183 */ - 0x03 - /* "yul_stack_opt/input.yul":167:187 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":197:206 */ - 0x04 - /* "yul_stack_opt/input.yul":190:210 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":220:229 */ - 0x05 - /* "yul_stack_opt/input.yul":213:233 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":243:252 */ - 0x06 - /* "yul_stack_opt/input.yul":236:256 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":266:275 */ - 0x07 - /* "yul_stack_opt/input.yul":259:279 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":289:298 */ - 0x08 - /* "yul_stack_opt/input.yul":282:302 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":312:321 */ - 0x09 - /* "yul_stack_opt/input.yul":305:325 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":335:344 */ - 0x0a - /* "yul_stack_opt/input.yul":328:348 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":358:368 */ - 0x0b - /* "yul_stack_opt/input.yul":351:372 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":382:392 */ - 0x0c - /* "yul_stack_opt/input.yul":375:396 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":406:416 */ - 0x0d - /* "yul_stack_opt/input.yul":399:420 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - dup2 - /* "yul_stack_opt/input.yul":129:141 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":151:160 */ - 0x02 - /* "yul_stack_opt/input.yul":144:164 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":174:183 */ - 0x03 - /* "yul_stack_opt/input.yul":167:187 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":197:206 */ - 0x04 - /* "yul_stack_opt/input.yul":190:210 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":220:229 */ - 0x05 - /* "yul_stack_opt/input.yul":213:233 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":243:252 */ - 0x06 - /* "yul_stack_opt/input.yul":236:256 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":266:275 */ - 0x07 - /* "yul_stack_opt/input.yul":259:279 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":289:298 */ - 0x08 - /* "yul_stack_opt/input.yul":282:302 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":312:321 */ - 0x09 - /* "yul_stack_opt/input.yul":305:325 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":335:344 */ - 0x0a - /* "yul_stack_opt/input.yul":328:348 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":358:368 */ - 0x0b - /* "yul_stack_opt/input.yul":351:372 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":382:392 */ - 0x0c - /* "yul_stack_opt/input.yul":375:396 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - /* "yul_stack_opt/input.yul":406:416 */ - 0x0d - /* "yul_stack_opt/input.yul":399:420 */ - sstore - /* "yul_stack_opt/input.yul":98:99 */ - dup1 - dup2 - /* "yul_stack_opt/input.yul":729:743 */ - sstore - pop diff --git a/test/cmdlineTests/yul_stack_opt_disabled/args b/test/cmdlineTests/yul_stack_opt_disabled/args deleted file mode 100644 index 2c89c24e0..000000000 --- a/test/cmdlineTests/yul_stack_opt_disabled/args +++ /dev/null @@ -1 +0,0 @@ ---strict-assembly diff --git a/test/cmdlineTests/yul_stack_opt_disabled/err b/test/cmdlineTests/yul_stack_opt_disabled/err deleted file mode 100644 index 3ff22e160..000000000 --- a/test/cmdlineTests/yul_stack_opt_disabled/err +++ /dev/null @@ -1,5 +0,0 @@ -Warning: Yul is still experimental. Please use the output with care. -Exception while assembling: -Dynamic exception type: -std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. -[solidity::util::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. diff --git a/test/cmdlineTests/yul_stack_opt_disabled/exit b/test/cmdlineTests/yul_stack_opt_disabled/exit deleted file mode 100644 index d00491fd7..000000000 --- a/test/cmdlineTests/yul_stack_opt_disabled/exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/test/cmdlineTests/yul_stack_opt_disabled/output b/test/cmdlineTests/yul_stack_opt_disabled/output deleted file mode 100644 index c65f6f367..000000000 --- a/test/cmdlineTests/yul_stack_opt_disabled/output +++ /dev/null @@ -1,30 +0,0 @@ - -======= yul_stack_opt_disabled/input.yul (EVM) ======= - -Pretty printed source: -object "object" { - code { - function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, n3, o3, p3 - { - let a := 1 - let b := 1 - let z3 := 1 - sstore(a, b) - sstore(add(a, 1), b) - sstore(add(a, 2), b) - sstore(add(a, 3), b) - sstore(add(a, 4), b) - sstore(add(a, 5), b) - sstore(add(a, 6), b) - sstore(add(a, 7), b) - sstore(add(a, 8), b) - sstore(add(a, 9), b) - sstore(add(a, 10), b) - sstore(add(a, 11), b) - sstore(add(a, 12), b) - } - let a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1 := fun() - let a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2 := fun() - sstore(a1, a2) - } -} From e3b345e5f0a35677a1bf81ab404118e6080d0546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 1 Jul 2021 17:29:24 +0200 Subject: [PATCH 5/5] Use a simpler stack optimization test to avoid having ICE message with absolute paths as expected output --- .../standard_yul_stack_opt/input.json | 41 +-- .../standard_yul_stack_opt/output.json | 307 +----------------- .../input.json | 29 +- .../output.json | 27 +- 4 files changed, 41 insertions(+), 363 deletions(-) diff --git a/test/cmdlineTests/standard_yul_stack_opt/input.json b/test/cmdlineTests/standard_yul_stack_opt/input.json index b9e5141ac..064fc2a84 100644 --- a/test/cmdlineTests/standard_yul_stack_opt/input.json +++ b/test/cmdlineTests/standard_yul_stack_opt/input.json @@ -5,43 +5,14 @@ "A": { "content": "{ - function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, n3, o3, p3 { - let a := 1 - let b := 1 - let z3 := 1 - sstore(a, b) - sstore(add(a, 1), b) - sstore(add(a, 2), b) - sstore(add(a, 3), b) - sstore(add(a, 4), b) - sstore(add(a, 5), b) - sstore(add(a, 6), b) - sstore(add(a, 7), b) - sstore(add(a, 8), b) - sstore(add(a, 9), b) - sstore(add(a, 10), b) - sstore(add(a, 11), b) - sstore(add(a, 12), b) - a3 := 1 - b3 := 1 - c3 := 1 - d3 := 1 - e3 := 1 - f3 := 1 - g3 := 1 - h3 := 1 - i3 := 1 - j3 := 1 - k3 := 1 - l3 := 1 - m3 := 1 - o3 := 1 - p3 := 1 + let x := 1 + sstore(0, x) + } + { + let y := 2 + sstore(32, y) } - let a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1 := fun() - let a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2 := fun() - sstore(a1, a2) }" } }, diff --git a/test/cmdlineTests/standard_yul_stack_opt/output.json b/test/cmdlineTests/standard_yul_stack_opt/output.json index 1e50cec28..0fd77310e 100644 --- a/test/cmdlineTests/standard_yul_stack_opt/output.json +++ b/test/cmdlineTests/standard_yul_stack_opt/output.json @@ -1,304 +1,17 @@ -{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":645:650 */ - tag_1 - tag_2 - jump\t// in -tag_1: - /* \"A\":575:650 */ - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - /* \"A\":722:727 */ - tag_3 - tag_2 - jump\t// in -tag_3: - /* \"A\":652:727 */ - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - pop - /* \"A\":740:742 */ +{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":16:17 */ + 0x01 dup1 - /* \"A\":736:738 */ - dup3 - /* \"A\":729:743 */ + /* \"A\":27:28 */ + 0x00 + /* \"A\":20:32 */ sstore pop - pop - /* \"A\":3:573 */ - jump(tag_4) -tag_2: - /* \"A\":98:99 */ - 0x01 - 0x01 - /* \"A\":129:141 */ - sstore - /* \"A\":98:99 */ - 0x01 - 0x01 - 0x01 - /* \"A\":151:160 */ - add - /* \"A\":144:164 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":181:182 */ + /* \"A\":50:51 */ 0x02 - /* \"A\":98:99 */ - 0x01 - /* \"A\":174:183 */ - add - /* \"A\":167:187 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":204:205 */ - 0x03 - /* \"A\":98:99 */ - 0x01 - /* \"A\":197:206 */ - add - /* \"A\":190:210 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":227:228 */ - 0x04 - /* \"A\":98:99 */ - 0x01 - /* \"A\":220:229 */ - add - /* \"A\":213:233 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":250:251 */ - 0x05 - /* \"A\":98:99 */ - 0x01 - /* \"A\":243:252 */ - add - /* \"A\":236:256 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":273:274 */ - 0x06 - /* \"A\":98:99 */ - 0x01 - /* \"A\":266:275 */ - add - /* \"A\":259:279 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":296:297 */ - 0x07 - /* \"A\":98:99 */ - 0x01 - /* \"A\":289:298 */ - add - /* \"A\":282:302 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":319:320 */ - 0x08 - /* \"A\":98:99 */ - 0x01 - /* \"A\":312:321 */ - add - /* \"A\":305:325 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":342:343 */ - 0x09 - /* \"A\":98:99 */ - 0x01 - /* \"A\":335:344 */ - add - /* \"A\":328:348 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":365:367 */ - 0x0a - /* \"A\":98:99 */ - 0x01 - /* \"A\":358:368 */ - add - /* \"A\":351:372 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":389:391 */ - 0x0b - /* \"A\":98:99 */ - 0x01 - /* \"A\":382:392 */ - add - /* \"A\":375:396 */ - sstore - /* \"A\":98:99 */ - 0x01 - /* \"A\":413:415 */ - 0x0c - /* \"A\":98:99 */ - 0x01 - /* \"A\":406:416 */ - add - /* \"A\":399:420 */ - sstore - /* \"A\":21:23 */ - 0x00 - /* \"A\":25:27 */ - 0x00 - /* \"A\":29:31 */ - 0x00 - /* \"A\":33:35 */ - 0x00 - /* \"A\":37:39 */ - 0x00 - /* \"A\":41:43 */ - 0x00 - /* \"A\":45:47 */ - 0x00 - /* \"A\":49:51 */ - 0x00 - /* \"A\":53:55 */ - 0x00 - /* \"A\":57:59 */ - 0x00 + dup1 /* \"A\":61:63 */ - 0x00 - /* \"A\":65:67 */ - 0x00 - /* \"A\":69:71 */ - 0x00 - /* \"A\":73:75 */ - 0x00 - /* \"A\":77:79 */ - 0x00 - /* \"A\":81:83 */ - 0x00 - /* \"A\":98:99 */ - 0x01 - /* \"A\":423:430 */ - swap16 + 0x20 + /* \"A\":54:67 */ + sstore pop - /* \"A\":98:99 */ - dup16 - /* \"A\":433:440 */ - swap15 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":443:450 */ - swap14 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":453:460 */ - swap13 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":463:470 */ - swap12 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":473:480 */ - swap11 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":483:490 */ - swap10 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":493:500 */ - swap9 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":503:510 */ - swap8 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":513:520 */ - swap7 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":523:530 */ - swap6 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":533:540 */ - swap5 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":543:550 */ - swap4 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":553:560 */ - swap2 - pop - /* \"A\":98:99 */ - dup16 - /* \"A\":563:570 */ - swap1 - pop - /* \"A\":85:573 */ -tag_5: - swap1 - swap2 - swap3 - swap4 - swap5 - swap6 - swap7 - swap8 - swap9 - swap10 - swap11 - swap12 - swap13 - swap14 - swap15 - swap16 - jump\t// out -tag_4: "}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]} diff --git a/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json b/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json index ad1057aea..6ed532c73 100644 --- a/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json +++ b/test/cmdlineTests/standard_yul_stack_opt_disabled/input.json @@ -5,30 +5,15 @@ "A": { "content": "{ - function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, n3, o3, p3 { - let a := 1 - let b := 1 - let z3 := 1 - sstore(a, b) - sstore(add(a, 1), b) - sstore(add(a, 2), b) - sstore(add(a, 3), b) - sstore(add(a, 4), b) - sstore(add(a, 5), b) - sstore(add(a, 6), b) - sstore(add(a, 7), b) - sstore(add(a, 8), b) - sstore(add(a, 9), b) - sstore(add(a, 10), b) - sstore(add(a, 11), b) - sstore(add(a, 12), b) + let x := 1 + sstore(0, x) } - let a1, b1, c1, d1, e1, f1, g1, h1, i1, j1, k1, l1, m1, n1, o1, p1 := fun() - let a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2 := fun() - sstore(a1, a2) -} -" + { + let y := 2 + sstore(32, y) + } +}" } }, "settings": diff --git a/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json b/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json index 9529dddc5..a4670cf26 100644 --- a/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json +++ b/test/cmdlineTests/standard_yul_stack_opt_disabled/output.json @@ -1,9 +1,18 @@ -{"errors":[{"component":"general","formattedMessage":"Internal exception in StandardCompiler::compile: /solidity/libyul/backends/evm/EVMObjectCompiler.cpp(70): Throw in function void solidity::yul::EVMObjectCompiler::run(solidity::yul::Object&, bool) -Dynamic exception type: boost::wrapexcept -std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. -[solidity::util::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. -","message":"Internal exception in StandardCompiler::compile: /solidity/libyul/backends/evm/EVMObjectCompiler.cpp(70): Throw in function void solidity::yul::EVMObjectCompiler::run(solidity::yul::Object&, bool) -Dynamic exception type: boost::wrapexcept -std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. -[solidity::util::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. -","severity":"error","type":"InternalCompilerError"}]} +{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":16:17 */ + 0x01 + dup1 + /* \"A\":27:28 */ + 0x00 + /* \"A\":20:32 */ + sstore + /* \"A\":50:51 */ + 0x02 + dup1 + /* \"A\":61:63 */ + 0x20 + /* \"A\":54:67 */ + sstore + /* \"A\":0:72 */ + pop + pop +"}}}},"errors":[{"component":"general","formattedMessage":"Yul is still experimental. Please use the output with care.","message":"Yul is still experimental. Please use the output with care.","severity":"warning","type":"Warning"}]}