diff --git a/test/cmdlineTests/evm_to_wasm/output b/test/cmdlineTests/evm_to_wasm/output index f8423bafe83e..0c1667982b12 100644 --- a/test/cmdlineTests/evm_to_wasm/output +++ b/test/cmdlineTests/evm_to_wasm/output @@ -3,7 +3,9 @@ Pretty printed source: object "object" { - code { { sstore(0, 1) } } + code { + { sstore(returndatasize(), 1) } + } } @@ -14,9 +16,10 @@ object "object" { code { function main() { - let _1 := 0 - mstore_internal(0:i32, _1, _1, _1, _1) - mstore_internal(32:i32, _1, _1, _1, 1) + let _1 := i64.extend_i32_u(eth.getReturnDataSize()) + let _2 := 0 + mstore_internal(0:i32, _2, _2, _2, _1) + mstore_internal(32:i32, _2, _2, _2, 1) eth.storageStore(0:i32, 32:i32) } function bswap16(x:i32) -> y:i32 @@ -45,20 +48,23 @@ object "object" { Binary representation: -0061736d01000000011b0560000060017e017e60017f017f60057f7e7e7e7e0060027f7f0002190108657468657265756d0c73746f7261676553746f7265000403060500020201030503010001060100071102066d656d6f72790200046d61696e00010ac001052901017e0240420021004100200020002000200010054120200020002000420110054100412010000b0b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100241107421022002200041107610027221010b20010b2201027e02402000a71003ad422086210220022000422088a71003ad8421010b20010b32000240200020011004370000200041086a20021004370000200041106a20031004370000200041186a200410043700000b0b +0061736d01000000011f066000006000017f60017e017e60017f017f60057f7e7e7e7e0060027f7f0002360208657468657265756d0c73746f7261676553746f7265000508657468657265756d1167657452657475726e4461746153697a65000103060500030302040503010001060100071102066d656d6f72790200046d61696e00020ac501052e01027e02401001ad2100420021014100200120012001200010064120200120012001420110064100412010000b0b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100341107421022002200041107610037221010b20010b2201027e02402000a71004ad422086210220022000422088a71004ad8421010b20010b32000240200020011005370000200041086a20021005370000200041106a20031005370000200041186a200410053700000b0b Text representation: (module (import "ethereum" "storageStore" (func $eth.storageStore (param i32 i32))) + (import "ethereum" "getReturnDataSize" (func $eth.getReturnDataSize (result i32))) (memory $memory (export "memory") 1) (export "main" (func $main)) (func $main (local $_1 i64) + (local $_2 i64) (block $label_ - (local.set $_1 (i64.const 0)) - (call $mstore_internal (i32.const 0) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)) - (call $mstore_internal (i32.const 32) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 1)) + (local.set $_1 (i64.extend_i32_u (call $eth.getReturnDataSize))) + (local.set $_2 (i64.const 0)) + (call $mstore_internal (i32.const 0) (local.get $_2) (local.get $_2) (local.get $_2) (local.get $_1)) + (call $mstore_internal (i32.const 32) (local.get $_2) (local.get $_2) (local.get $_2) (i64.const 1)) (call $eth.storageStore (i32.const 0) (i32.const 32)) ) ) diff --git a/test/cmdlineTests/evm_to_wasm_break/output b/test/cmdlineTests/evm_to_wasm_break/output index 370eff7275dc..45dc9114fdcd 100644 --- a/test/cmdlineTests/evm_to_wasm_break/output +++ b/test/cmdlineTests/evm_to_wasm_break/output @@ -5,13 +5,13 @@ Pretty printed source: object "object" { code { { - let x := calldataload(0) + let x := calldataload(returndatasize()) for { } lt(x, 10) { x := add(x, 1) } { if eq(x, 2) { break } if eq(x, 4) { continue } } - sstore(0, x) + sstore(returndatasize(), x) } } } @@ -24,32 +24,34 @@ object "object" { code { function main() { - let _1 := 0 - let x, x_1, x_2, x_3 := calldataload(_1, _1, _1, _1) + let _1, _2, _3, _4 := returndatasize_887() + let x, x_1, x_2, x_3 := calldataload(_1, _2, _3, _4) let x_4 := x let x_5 := x_1 let x_6 := x_2 let x_7 := x_3 - let _2 := 1 - let _3:i32 := i32.eqz(i32.eqz(i64.eqz(i64.or(i64.or(_1, _1), i64.or(_1, _2))))) + let _5 := 1 + let _6 := 0 + let _7:i32 := i32.eqz(i32.eqz(i64.eqz(i64.or(i64.or(_6, _6), i64.or(_6, _5))))) for { } - i32.eqz(_3) + i32.eqz(_7) { - let x_8, x_9, x_10, x_11 := add(x_4, x_5, x_6, x_7, _1, _1, _1, _2) + let x_8, x_9, x_10, x_11 := add(x_4, x_5, x_6, x_7, _6, _6, _6, _5) x_4 := x_8 x_5 := x_9 x_6 := x_10 x_7 := x_11 } { - let _4, _5, _6, _7 := iszero_887(_1, _1, _1, lt(x_4, x_5, x_6, x_7, _1, _1, _1, 10)) - if i32.eqz(i64.eqz(i64.or(i64.or(_4, _5), i64.or(_6, _7)))) { break } - let _8, _9, _10, _11 := eq_888(x_4, x_5, x_6, x_7, _1, _1, _1, 2) + let _8, _9, _10, _11 := iszero_884(_6, _6, _6, lt(x_4, x_5, x_6, x_7, _6, _6, _6, 10)) if i32.eqz(i64.eqz(i64.or(i64.or(_8, _9), i64.or(_10, _11)))) { break } - let _12, _13, _14, _15 := eq_888(x_4, x_5, x_6, x_7, _1, _1, _1, 4) - if i32.eqz(i64.eqz(i64.or(i64.or(_12, _13), i64.or(_14, _15)))) { continue } + let _12, _13, _14, _15 := eq_885(x_4, x_5, x_6, x_7, _6, _6, _6, 2) + if i32.eqz(i64.eqz(i64.or(i64.or(_12, _13), i64.or(_14, _15)))) { break } + let _16, _17, _18, _19 := eq_885(x_4, x_5, x_6, x_7, _6, _6, _6, 4) + if i32.eqz(i64.eqz(i64.or(i64.or(_16, _17), i64.or(_18, _19)))) { continue } } - sstore(_1, _1, _1, _1, x_4, x_5, x_6, x_7) + let _20, _21, _22, _23 := returndatasize_887() + sstore(_20, _21, _22, _23, x_4, x_5, x_6, x_7) } function add_carry(x, y, c) -> r, r_c { @@ -68,11 +70,11 @@ object "object" { let r1_1, carry_2 := add_carry(x1, y1, carry_1) r1 := r1_1 } - function iszero_887(x1, x2, x3, x4) -> r1, r2, r3, r4 + function iszero_884(x1, x2, x3, x4) -> r1, r2, r3, r4 { r4 := i64.extend_i32_u(i64.eqz(i64.or(i64.or(x1, x2), i64.or(x3, x4)))) } - function eq_888(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 + function eq_885(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 { r4 := i64.extend_i32_u(i32.and(i64.eq(x1, y1), i32.and(i64.eq(x2, y2), i32.and(i64.eq(x3, y3), i64.eq(x4, y4))))) } @@ -150,6 +152,10 @@ object "object" { z3 := z3_1 z4 := z4_1 } + function returndatasize_887() -> z1, z2, z3, z4 + { + z4 := i64.extend_i32_u(eth.getReturnDataSize()) + } function sstore(x1, x2, x3, x4, y1, y2, y3, y4) { mstore_internal(0:i32, x1, x2, x3, x4) @@ -168,7 +174,7 @@ object "object" { Binary representation: -0061736d0100000001530c6000006000017f60017e017e60037e7e7e017e60047e7e7e7e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60017f017f60057f7e7e7e7e0060027f7f0060037f7f7f00025e0408657468657265756d0c73746f7261676553746f7265000a08657468657265756d06726576657274000a08657468657265756d0f67657443616c6c4461746153697a65000108657468657265756d0c63616c6c44617461436f7079000b030e0d0003070407070508080204060905030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00040ac0090dcb02030a7e017f107e02404200210002402000200020002000100e21012300210223012103230221040b20012105200221062003210720042108420121092000200084200020098484504545210a02400340200a45450d01024002402000200020002005200620072008200020002000420a10091007210b2300210c2301210d2302210e0b200b200c84200d200e8484504504400c030b0240200520062007200820002000200042021008210f2300211023012111230221120b200f201084201120128484504504400c030b024020052006200720082000200020004204100821132300211423012115230221160b2013201484201520168484504504400c010b0b0240200520062007200820002000200020091006211723002118230121192302211a0b201721052018210620192107201a21080c000b0b20002000200020002005200620072008100f0b0b2901037e0240200020017c2105200520027c21032005200054200320055472ad21040b2004240020030b6c010b7e0240200320077c210c200c42007c210b024020022006200c200354200b200c5472ad1005210d2300210e0b200d210a024020012005200e1005210f230021100b200f2109024020002004201010052111230021120b201121080b20092400200a2401200b240220080b2401047e0240200020018420022003848450ad21070b20052400200624012007240220040b2f01047e02402000200451200120055120022006512003200751717171ad210b0b20092400200a2401200b240220080ba30102017e057f024041002109417f210a0240200a200020045220002004541b210b200b41004604400240200a200120055220012005541b210c200c41004604400240200a200220065220022006541b210d200d41004604402003200754210905200d41014604404100210905410121090b0b0b05200c41014604404100210905410121090b0b0b05200b41014604404100210905410121090b0b0b2009ad21080b20080b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100b411074210220022000411076100b7221010b20010b2201027e02402000a7100cad422086210220022000422088a7100cad8421010b20010bfc0105047e017f017e087f047e024010022108420021092009200920092009100a210a2000200120022003100a210b2009200920094220100a210c200b417f200c6b4b04404100410010010b2008200b6b210d200b20084b04404100210d0b4100210e200d200e4b0440200a200b200d10030b200c200d4b0440200c200d6b210f200a200d6a2110200e2111024003402011200f49450d010240201020116a200e3a00000b201141016a21110c000b0b0b200e290000100d2112200e41086a290000100d2113200e41106a290000100d2114200e41186a290000100d2115201221042013210520142106201521070b20052400200624012007240220040b230002404100200020012002200310104120200420052006200710104100412010000b0b3200024020002001100d370000200041086a2002100d370000200041106a2003100d370000200041186a2004100d3700000b0b +0061736d0100000001570d6000006000017e6000017f60017e017e60037e7e7e017e60047e7e7e7e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60017f017f60057f7e7e7e7e0060027f7f0060037f7f7f00027b0508657468657265756d0c73746f7261676553746f7265000b08657468657265756d06726576657274000b08657468657265756d0f67657443616c6c4461746153697a65000208657468657265756d0c63616c6c44617461436f7079000c08657468657265756d1167657452657475726e4461746153697a650002030f0e000408050808060909030501070a0503010001061f067f0141000b7f0141000b7f0141000b7e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00050a810a0ef102030e7e017f147e02400240101021002300210123012102230221030b02402000200120022003100f21042303210523042106230521070b20042108200521092006210a2007210b4201210c4200210d200d200d84200d200c8484504545210e02400340200e45450d0102400240200d200d200d20082009200a200b200d200d200d420a100a1008210f2303211023042111230521120b200f201084201120128484504504400c030b024020082009200a200b200d200d200d4202100921132303211423042115230521160b2013201484201520168484504504400c030b024020082009200a200b200d200d200d42041009211723032118230421192305211a0b20172018842019201a8484504504400c010b0b024020082009200a200b200d200d200d200c1007211b2303211c2304211d2305211e0b201b2108201c2109201d210a201e210b0c000b0b02401010211f2303212023042121230521220b201f20202021202220082009200a200b10110b0b2901037e0240200020017c2105200520027c21032005200054200320055472ad21040b2004240320030b6c010b7e0240200320077c210c200c42007c210b024020022006200c200354200b200c5472ad1006210d2303210e0b200d210a024020012005200e1006210f230321100b200f2109024020002004201010062111230321120b201121080b20092403200a2404200b240520080b2401047e0240200020018420022003848450ad21070b20052403200624042007240520040b2f01047e02402000200451200120055120022006512003200751717171ad210b0b20092403200a2404200b240520080ba30102017e057f024041002109417f210a0240200a200020045220002004541b210b200b41004604400240200a200120055220012005541b210c200c41004604400240200a200220065220022006541b210d200d41004604402003200754210905200d41014604404100210905410121090b0b0b05200c41014604404100210905410121090b0b0b05200b41014604404100210905410121090b0b0b2009ad21080b20080b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100c411074210220022000411076100c7221010b20010b2201027e02402000a7100dad422086210220022000422088a7100dad8421010b20010bfc0105047e017f017e087f047e024010022108420021092009200920092009100b210a2000200120022003100b210b2009200920094220100b210c200b417f200c6b4b04404100410010010b2008200b6b210d200b20084b04404100210d0b4100210e200d200e4b0440200a200b200d10030b200c200d4b0440200c200d6b210f200a200d6a2110200e2111024003402011200f49450d010240201020116a200e3a00000b201141016a21110c000b0b0b200e290000100e2112200e41086a290000100e2113200e41106a290000100e2114200e41186a290000100e2115201221042013210520142106201521070b20052403200624042007240520040b1a01047e02401004ad21030b20012403200224042003240520000b230002404100200020012002200310124120200420052006200710124100412010000b0b3200024020002001100e370000200041086a2002100e370000200041106a2003100e370000200041186a2004100e3700000b0b Text representation: (module @@ -176,14 +182,21 @@ Text representation: (import "ethereum" "revert" (func $eth.revert (param i32 i32))) (import "ethereum" "getCallDataSize" (func $eth.getCallDataSize (result i32))) (import "ethereum" "callDataCopy" (func $eth.callDataCopy (param i32 i32 i32))) + (import "ethereum" "getReturnDataSize" (func $eth.getReturnDataSize (result i32))) (memory $memory (export "memory") 1) (export "main" (func $main)) - (global $global_ (mut i64) (i64.const 0)) - (global $global__1 (mut i64) (i64.const 0)) - (global $global__2 (mut i64) (i64.const 0)) + (global $global_ (mut i32) (i32.const 0)) + (global $global__1 (mut i32) (i32.const 0)) + (global $global__2 (mut i32) (i32.const 0)) + (global $global__3 (mut i64) (i64.const 0)) + (global $global__4 (mut i64) (i64.const 0)) + (global $global__5 (mut i64) (i64.const 0)) (func $main (local $_1 i64) + (local $_2 i64) + (local $_3 i64) + (local $_4 i64) (local $x i64) (local $x_1 i64) (local $x_2 i64) @@ -192,12 +205,9 @@ Text representation: (local $x_5 i64) (local $x_6 i64) (local $x_7 i64) - (local $_2 i64) - (local $_3 i32) - (local $_4 i64) (local $_5 i64) (local $_6 i64) - (local $_7 i64) + (local $_7 i32) (local $_8 i64) (local $_9 i64) (local $_10 i64) @@ -206,77 +216,99 @@ Text representation: (local $_13 i64) (local $_14 i64) (local $_15 i64) + (local $_16 i64) + (local $_17 i64) + (local $_18 i64) + (local $_19 i64) (local $x_8 i64) (local $x_9 i64) (local $x_10 i64) (local $x_11 i64) + (local $_20 i64) + (local $_21 i64) + (local $_22 i64) + (local $_23 i64) (block $label_ - (local.set $_1 (i64.const 0)) (block - (local.set $x (call $calldataload (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))) - (local.set $x_1 (global.get $global_)) - (local.set $x_2 (global.get $global__1)) - (local.set $x_3 (global.get $global__2)) + (local.set $_1 (call $returndatasize_887)) + (local.set $_2 (global.get $global_)) + (local.set $_3 (global.get $global__1)) + (local.set $_4 (global.get $global__2)) + + ) + (block + (local.set $x (call $calldataload (local.get $_1) (local.get $_2) (local.get $_3) (local.get $_4))) + (local.set $x_1 (global.get $global__3)) + (local.set $x_2 (global.get $global__4)) + (local.set $x_3 (global.get $global__5)) ) (local.set $x_4 (local.get $x)) (local.set $x_5 (local.get $x_1)) (local.set $x_6 (local.get $x_2)) (local.set $x_7 (local.get $x_3)) - (local.set $_2 (i64.const 1)) - (local.set $_3 (i32.eqz (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_1) (local.get $_1)) (i64.or (local.get $_1) (local.get $_2))))))) - (block $label__3 - (loop $label__5 - (br_if $label__3 (i32.eqz (i32.eqz (local.get $_3)))) - (block $label__4 + (local.set $_5 (i64.const 1)) + (local.set $_6 (i64.const 0)) + (local.set $_7 (i32.eqz (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_6) (local.get $_6)) (i64.or (local.get $_6) (local.get $_5))))))) + (block $label__6 + (loop $label__8 + (br_if $label__6 (i32.eqz (i32.eqz (local.get $_7)))) + (block $label__7 (block - (local.set $_4 (call $iszero_887 (local.get $_1) (local.get $_1) (local.get $_1) (call $lt (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 10)))) - (local.set $_5 (global.get $global_)) - (local.set $_6 (global.get $global__1)) - (local.set $_7 (global.get $global__2)) + (local.set $_8 (call $iszero_884 (local.get $_6) (local.get $_6) (local.get $_6) (call $lt (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_6) (local.get $_6) (local.get $_6) (i64.const 10)))) + (local.set $_9 (global.get $global__3)) + (local.set $_10 (global.get $global__4)) + (local.set $_11 (global.get $global__5)) ) - (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_4) (local.get $_5)) (i64.or (local.get $_6) (local.get $_7))))) (then - (br $label__3) + (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_8) (local.get $_9)) (i64.or (local.get $_10) (local.get $_11))))) (then + (br $label__6) )) (block - (local.set $_8 (call $eq_888 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 2))) - (local.set $_9 (global.get $global_)) - (local.set $_10 (global.get $global__1)) - (local.set $_11 (global.get $global__2)) + (local.set $_12 (call $eq_885 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_6) (local.get $_6) (local.get $_6) (i64.const 2))) + (local.set $_13 (global.get $global__3)) + (local.set $_14 (global.get $global__4)) + (local.set $_15 (global.get $global__5)) ) - (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_8) (local.get $_9)) (i64.or (local.get $_10) (local.get $_11))))) (then - (br $label__3) + (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_12) (local.get $_13)) (i64.or (local.get $_14) (local.get $_15))))) (then + (br $label__6) )) (block - (local.set $_12 (call $eq_888 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 4))) - (local.set $_13 (global.get $global_)) - (local.set $_14 (global.get $global__1)) - (local.set $_15 (global.get $global__2)) + (local.set $_16 (call $eq_885 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_6) (local.get $_6) (local.get $_6) (i64.const 4))) + (local.set $_17 (global.get $global__3)) + (local.set $_18 (global.get $global__4)) + (local.set $_19 (global.get $global__5)) ) - (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_12) (local.get $_13)) (i64.or (local.get $_14) (local.get $_15))))) (then - (br $label__4) + (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_16) (local.get $_17)) (i64.or (local.get $_18) (local.get $_19))))) (then + (br $label__7) )) ) (block - (local.set $x_8 (call $add (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_2))) - (local.set $x_9 (global.get $global_)) - (local.set $x_10 (global.get $global__1)) - (local.set $x_11 (global.get $global__2)) + (local.set $x_8 (call $add (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_6) (local.get $_6) (local.get $_6) (local.get $_5))) + (local.set $x_9 (global.get $global__3)) + (local.set $x_10 (global.get $global__4)) + (local.set $x_11 (global.get $global__5)) ) (local.set $x_4 (local.get $x_8)) (local.set $x_5 (local.get $x_9)) (local.set $x_6 (local.get $x_10)) (local.set $x_7 (local.get $x_11)) - (br $label__5) + (br $label__8) ) ) - (call $sstore (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7)) + (block + (local.set $_20 (call $returndatasize_887)) + (local.set $_21 (global.get $global__3)) + (local.set $_22 (global.get $global__4)) + (local.set $_23 (global.get $global__5)) + + ) + (call $sstore (local.get $_20) (local.get $_21) (local.get $_22) (local.get $_23) (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7)) ) ) @@ -288,13 +320,13 @@ Text representation: (local $r i64) (local $r_c i64) (local $t i64) - (block $label__6 + (block $label__9 (local.set $t (i64.add (local.get $x) (local.get $y))) (local.set $r (i64.add (local.get $t) (local.get $c))) (local.set $r_c (i64.extend_i32_u (i32.or (i64.lt_u (local.get $t) (local.get $x)) (i64.lt_u (local.get $r) (local.get $t))))) ) - (global.set $global_ (local.get $r_c)) + (global.set $global__3 (local.get $r_c)) (local.get $r) ) @@ -319,36 +351,36 @@ Text representation: (local $carry_1 i64) (local $r1_1 i64) (local $carry_2 i64) - (block $label__7 + (block $label__10 (local.set $t (i64.add (local.get $x4) (local.get $y4))) (local.set $r4 (i64.add (local.get $t) (i64.const 0))) (block (local.set $r3_1 (call $add_carry (local.get $x3) (local.get $y3) (i64.extend_i32_u (i32.or (i64.lt_u (local.get $t) (local.get $x4)) (i64.lt_u (local.get $r4) (local.get $t)))))) - (local.set $carry (global.get $global_)) + (local.set $carry (global.get $global__3)) ) (local.set $r3 (local.get $r3_1)) (block (local.set $r2_1 (call $add_carry (local.get $x2) (local.get $y2) (local.get $carry))) - (local.set $carry_1 (global.get $global_)) + (local.set $carry_1 (global.get $global__3)) ) (local.set $r2 (local.get $r2_1)) (block (local.set $r1_1 (call $add_carry (local.get $x1) (local.get $y1) (local.get $carry_1))) - (local.set $carry_2 (global.get $global_)) + (local.set $carry_2 (global.get $global__3)) ) (local.set $r1 (local.get $r1_1)) ) - (global.set $global_ (local.get $r2)) - (global.set $global__1 (local.get $r3)) - (global.set $global__2 (local.get $r4)) + (global.set $global__3 (local.get $r2)) + (global.set $global__4 (local.get $r3)) + (global.set $global__5 (local.get $r4)) (local.get $r1) ) -(func $iszero_887 +(func $iszero_884 (param $x1 i64) (param $x2 i64) (param $x3 i64) @@ -358,17 +390,17 @@ Text representation: (local $r2 i64) (local $r3 i64) (local $r4 i64) - (block $label__8 + (block $label__11 (local.set $r4 (i64.extend_i32_u (i64.eqz (i64.or (i64.or (local.get $x1) (local.get $x2)) (i64.or (local.get $x3) (local.get $x4)))))) ) - (global.set $global_ (local.get $r2)) - (global.set $global__1 (local.get $r3)) - (global.set $global__2 (local.get $r4)) + (global.set $global__3 (local.get $r2)) + (global.set $global__4 (local.get $r3)) + (global.set $global__5 (local.get $r4)) (local.get $r1) ) -(func $eq_888 +(func $eq_885 (param $x1 i64) (param $x2 i64) (param $x3 i64) @@ -382,13 +414,13 @@ Text representation: (local $r2 i64) (local $r3 i64) (local $r4 i64) - (block $label__9 + (block $label__12 (local.set $r4 (i64.extend_i32_u (i32.and (i64.eq (local.get $x1) (local.get $y1)) (i32.and (i64.eq (local.get $x2) (local.get $y2)) (i32.and (i64.eq (local.get $x3) (local.get $y3)) (i64.eq (local.get $x4) (local.get $y4))))))) ) - (global.set $global_ (local.get $r2)) - (global.set $global__1 (local.get $r3)) - (global.set $global__2 (local.get $r4)) + (global.set $global__3 (local.get $r2)) + (global.set $global__4 (local.get $r3)) + (global.set $global__5 (local.get $r4)) (local.get $r1) ) @@ -406,23 +438,23 @@ Text representation: (local $z i32) (local $_1 i32) (local $condition i32) - (local $condition_11 i32) - (local $condition_12 i32) - (block $label__10 + (local $condition_14 i32) + (local $condition_15 i32) + (block $label__13 (local.set $z (i32.const 0)) (local.set $_1 (i32.const 4294967295)) (block (local.set $condition (select (local.get $_1) (i64.ne (local.get $x1) (local.get $y1)) (i64.lt_u (local.get $x1) (local.get $y1)))) (if (i32.eq (local.get $condition) (i32.const 0)) (then (block - (local.set $condition_11 (select (local.get $_1) (i64.ne (local.get $x2) (local.get $y2)) (i64.lt_u (local.get $x2) (local.get $y2)))) - (if (i32.eq (local.get $condition_11) (i32.const 0)) (then + (local.set $condition_14 (select (local.get $_1) (i64.ne (local.get $x2) (local.get $y2)) (i64.lt_u (local.get $x2) (local.get $y2)))) + (if (i32.eq (local.get $condition_14) (i32.const 0)) (then (block - (local.set $condition_12 (select (local.get $_1) (i64.ne (local.get $x3) (local.get $y3)) (i64.lt_u (local.get $x3) (local.get $y3)))) - (if (i32.eq (local.get $condition_12) (i32.const 0)) (then + (local.set $condition_15 (select (local.get $_1) (i64.ne (local.get $x3) (local.get $y3)) (i64.lt_u (local.get $x3) (local.get $y3)))) + (if (i32.eq (local.get $condition_15) (i32.const 0)) (then (local.set $z (i64.lt_u (local.get $x4) (local.get $y4))) )(else - (if (i32.eq (local.get $condition_12) (i32.const 1)) (then + (if (i32.eq (local.get $condition_15) (i32.const 1)) (then (local.set $z (i32.const 0)) )(else (local.set $z (i32.const 1)) @@ -431,7 +463,7 @@ Text representation: ) )(else - (if (i32.eq (local.get $condition_11) (i32.const 1)) (then + (if (i32.eq (local.get $condition_14) (i32.const 1)) (then (local.set $z (i32.const 0)) )(else (local.set $z (i32.const 1)) @@ -461,7 +493,7 @@ Text representation: (param $x4 i64) (result i32) (local $v i32) - (block $label__13 + (block $label__16 (if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then (unreachable))) (if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then @@ -476,7 +508,7 @@ Text representation: (param $x i32) (result i32) (local $y i32) - (block $label__14 + (block $label__17 (local.set $y (i32.or (i32.and (i32.shl (local.get $x) (i32.const 8)) (i32.const 65280)) (i32.and (i32.shr_u (local.get $x) (i32.const 8)) (i32.const 255)))) ) @@ -488,7 +520,7 @@ Text representation: (result i32) (local $y i32) (local $hi i32) - (block $label__15 + (block $label__18 (local.set $hi (i32.shl (call $bswap16 (local.get $x)) (i32.const 16))) (local.set $y (i32.or (local.get $hi) (call $bswap16 (i32.shr_u (local.get $x) (i32.const 16))))) @@ -501,7 +533,7 @@ Text representation: (result i64) (local $y i64) (local $hi i64) - (block $label__16 + (block $label__19 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (local.get $x)))) (i64.const 32))) (local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (local.get $x) (i64.const 32))))))) @@ -533,7 +565,7 @@ Text representation: (local $z2_1 i64) (local $z3_1 i64) (local $z4_1 i64) - (block $label__17 + (block $label__20 (local.set $cds (call $eth.getCallDataSize)) (local.set $_1 (i64.const 0)) (local.set $destination (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))) @@ -552,14 +584,14 @@ Text representation: (local.set $_3 (i32.sub (local.get $requested_size) (local.get $available_size))) (local.set $_4 (i32.add (local.get $destination) (local.get $available_size))) (local.set $i (local.get $_2)) - (block $label__18 - (loop $label__20 - (br_if $label__18 (i32.eqz (i32.lt_u (local.get $i) (local.get $_3)))) - (block $label__19 + (block $label__21 + (loop $label__23 + (br_if $label__21 (i32.eqz (i32.lt_u (local.get $i) (local.get $_3)))) + (block $label__22 (i32.store8 (i32.add (local.get $_4) (local.get $i)) (local.get $_2)) ) (local.set $i (i32.add (local.get $i) (i32.const 1))) - (br $label__20) + (br $label__23) ) ) @@ -574,9 +606,25 @@ Text representation: (local.set $z4 (local.get $z4_1)) ) - (global.set $global_ (local.get $z2)) - (global.set $global__1 (local.get $z3)) - (global.set $global__2 (local.get $z4)) + (global.set $global__3 (local.get $z2)) + (global.set $global__4 (local.get $z3)) + (global.set $global__5 (local.get $z4)) + (local.get $z1) +) + +(func $returndatasize_887 + (result i64) + (local $z1 i64) + (local $z2 i64) + (local $z3 i64) + (local $z4 i64) + (block $label__24 + (local.set $z4 (i64.extend_i32_u (call $eth.getReturnDataSize))) + + ) + (global.set $global__3 (local.get $z2)) + (global.set $global__4 (local.get $z3)) + (global.set $global__5 (local.get $z4)) (local.get $z1) ) @@ -589,7 +637,7 @@ Text representation: (param $y2 i64) (param $y3 i64) (param $y4 i64) - (block $label__21 + (block $label__25 (call $mstore_internal (i32.const 0) (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $mstore_internal (i32.const 32) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) (call $eth.storageStore (i32.const 0) (i32.const 32)) @@ -602,7 +650,7 @@ Text representation: (param $y2 i64) (param $y3 i64) (param $y4 i64) - (block $label__22 + (block $label__26 (i64.store (local.get $pos) (call $bswap64 (local.get $y1))) (i64.store (i32.add (local.get $pos) (i32.const 8)) (call $bswap64 (local.get $y2))) (i64.store (i32.add (local.get $pos) (i32.const 16)) (call $bswap64 (local.get $y3))) diff --git a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output index 418676634492..db0b1c34408b 100644 --- a/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output +++ b/test/cmdlineTests/ir_compiler_inheritance_nosubobjects/output @@ -10,17 +10,20 @@ object "C_7" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_7_deployed") - codecopy(0, dataoffset("C_7_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_7_deployed"), _1) + return(returndatasize(), _1) } } object "C_7_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } @@ -38,17 +41,20 @@ object "D_10" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("D_10_deployed") - codecopy(0, dataoffset("D_10_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("D_10_deployed"), _1) + return(returndatasize(), _1) } } object "D_10_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } diff --git a/test/cmdlineTests/ir_compiler_subobjects/output b/test/cmdlineTests/ir_compiler_subobjects/output index ee9ae8138e68..d029fca857a3 100644 --- a/test/cmdlineTests/ir_compiler_subobjects/output +++ b/test/cmdlineTests/ir_compiler_subobjects/output @@ -10,17 +10,20 @@ object "C_3" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_3_deployed"), _1) + return(returndatasize(), _1) } } object "C_3_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } @@ -38,10 +41,13 @@ object "D_16" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("D_16_deployed") - codecopy(0, dataoffset("D_16_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("D_16_deployed"), _1) + return(returndatasize(), _1) } } object "D_16_deployed" { @@ -50,7 +56,7 @@ object "D_16" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0x26121ff0, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -87,17 +93,20 @@ object "D_16" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_3_deployed"), _1) + return(returndatasize(), _1) } } object "C_3_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output index e4ad6b29860a..06bde13487af 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_creation/output @@ -10,10 +10,13 @@ object "D_12" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("D_12_deployed") - codecopy(0, dataoffset("D_12_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("D_12_deployed"), _1) + return(returndatasize(), _1) } } object "D_12_deployed" { @@ -22,7 +25,7 @@ object "D_12" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0x26121ff0, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -31,7 +34,7 @@ object "D_12" { return(128, _1) } } - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } diff --git a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output index cf559e4bdcd1..ce56ccfa7635 100644 --- a/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output +++ b/test/cmdlineTests/ir_with_assembly_no_memoryguard_runtime/output @@ -10,10 +10,13 @@ object "D_8" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("D_8_deployed") - codecopy(0, dataoffset("D_8_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("D_8_deployed"), _1) + return(returndatasize(), _1) } } object "D_8_deployed" { @@ -22,7 +25,7 @@ object "D_8" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0x26121ff0, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -31,7 +34,7 @@ object "D_8" { return(128, _1) } } - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } diff --git a/test/cmdlineTests/name_simplifier/output b/test/cmdlineTests/name_simplifier/output index 56e382e25527..7e23153d69dc 100644 --- a/test/cmdlineTests/name_simplifier/output +++ b/test/cmdlineTests/name_simplifier/output @@ -10,10 +10,13 @@ object "C_59" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_59_deployed") - codecopy(0, dataoffset("C_59_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_59_deployed"), _1) + return(returndatasize(), _1) } } object "C_59_deployed" { @@ -22,7 +25,7 @@ object "C_59" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0xf8eddcc6, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -56,7 +59,7 @@ object "C_59" { return(memPos, sub(abi_encode_uint256_string(memPos, ret, ret_1), memPos)) } } - revert(0, 0) + revert(returndatasize(), returndatasize()) } function abi_encode_uint256_string(headStart, value0, value1) -> tail { @@ -65,14 +68,14 @@ object "C_59" { mstore(add(headStart, _1), 64) let length := mload(value1) mstore(add(headStart, 64), length) - let i := tail + let i := returndatasize() for { } lt(i, length) { i := add(i, _1) } { mstore(add(add(headStart, i), 96), mload(add(add(value1, i), _1))) } if gt(i, length) { - mstore(add(add(headStart, length), 96), tail) + mstore(add(add(headStart, length), 96), returndatasize()) } tail := add(add(headStart, and(add(length, 31), not(31))), 96) } @@ -117,21 +120,21 @@ object "C_59" { } function panic_error_0x32() { - mstore(0, shl(224, 0x4e487b71)) + mstore(returndatasize(), shl(224, 0x4e487b71)) mstore(4, 0x32) - revert(0, 0x24) + revert(returndatasize(), 0x24) } function panic_error_0x41() { - mstore(0, shl(224, 0x4e487b71)) + mstore(returndatasize(), shl(224, 0x4e487b71)) mstore(4, 0x41) - revert(0, 0x24) + revert(returndatasize(), 0x24) } function storage_array_index_access_struct_S(array, index) -> slot, offset { if iszero(lt(index, 0x02)) { panic_error_0x32() } slot := add(array, index) - offset := offset + offset := returndatasize() } } } diff --git a/test/cmdlineTests/object_compiler/output b/test/cmdlineTests/object_compiler/output index 66ad61fb75d7..7937224612c5 100644 --- a/test/cmdlineTests/object_compiler/output +++ b/test/cmdlineTests/object_compiler/output @@ -5,17 +5,17 @@ Pretty printed source: object "MyContract" { code { { - sstore(0, caller()) + sstore(returndatasize(), caller()) let _1 := datasize("Runtime") - datacopy(0, dataoffset("Runtime"), _1) - return(0, _1) + datacopy(returndatasize(), dataoffset("Runtime"), _1) + return(returndatasize(), _1) } } object "Runtime" { code { { - mstore(0, sload(0)) - return(0, 0x20) + mstore(returndatasize(), sload(returndatasize())) + return(returndatasize(), 0x20) } } } @@ -23,13 +23,13 @@ object "MyContract" { Binary representation: -33600055600b806012600039806000f350fe60005460005260206000f3 +333d55600880600f3d39803df350fe3d543d5260203df3 Text representation: /* "object_compiler/input.yul":128:136 */ caller /* "object_compiler/input.yul":125:126 */ - 0x00 + returndatasize /* "object_compiler/input.yul":118:137 */ sstore dataSize(sub_0) @@ -37,13 +37,13 @@ Text representation: dup1 dataOffset(sub_0) /* "object_compiler/input.yul":125:126 */ - 0x00 + returndatasize /* "object_compiler/input.yul":205:260 */ codecopy /* "object_compiler/input.yul":275:294 */ dup1 /* "object_compiler/input.yul":125:126 */ - 0x00 + returndatasize /* "object_compiler/input.yul":265:295 */ return pop @@ -51,17 +51,17 @@ stop sub_0: assembly { /* "object_compiler/input.yul":397:398 */ - 0x00 + returndatasize /* "object_compiler/input.yul":391:399 */ sload /* "object_compiler/input.yul":397:398 */ - 0x00 + returndatasize /* "object_compiler/input.yul":381:400 */ mstore /* "object_compiler/input.yul":417:421 */ 0x20 /* "object_compiler/input.yul":397:398 */ - 0x00 + returndatasize /* "object_compiler/input.yul":407:422 */ return } diff --git a/test/cmdlineTests/optimizer_array_sload/output b/test/cmdlineTests/optimizer_array_sload/output index ecf8fdb4c9f8..00224715e19e 100644 --- a/test/cmdlineTests/optimizer_array_sload/output +++ b/test/cmdlineTests/optimizer_array_sload/output @@ -10,10 +10,13 @@ object "Arraysum_34" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("Arraysum_34_deployed") - codecopy(0, dataoffset("Arraysum_34_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("Arraysum_34_deployed"), _1) + return(returndatasize(), _1) } } object "Arraysum_34_deployed" { @@ -22,7 +25,7 @@ object "Arraysum_34" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0x81d73423, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -44,7 +47,7 @@ object "Arraysum_34" { return(memPos, sub(abi_encode_uint256(memPos, var_sum), memPos)) } } - revert(0, 0) + revert(returndatasize(), returndatasize()) } function abi_encode_uint256(headStart, value0) -> tail { @@ -57,9 +60,9 @@ object "Arraysum_34" { let newFreePtr := add(memPtr, and(add(size, 31), not(31))) if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { - mstore(0, shl(224, 0x4e487b71)) + mstore(returndatasize(), shl(224, 0x4e487b71)) mstore(4, 0x41) - revert(0, 0x24) + revert(returndatasize(), 0x24) } mstore(64, newFreePtr) } @@ -70,9 +73,9 @@ object "Arraysum_34" { } function panic_error_0x11() { - mstore(0, shl(224, 0x4e487b71)) + mstore(returndatasize(), shl(224, 0x4e487b71)) mstore(4, 0x11) - revert(0, 0x24) + revert(returndatasize(), 0x24) } } } diff --git a/test/cmdlineTests/standard_ewasm_requested/output.json b/test/cmdlineTests/standard_ewasm_requested/output.json index c7c994435ff5..2f845b08fadd 100644 --- a/test/cmdlineTests/standard_ewasm_requested/output.json +++ b/test/cmdlineTests/standard_ewasm_requested/output.json @@ -1,43 +1,87 @@ -{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d01000000013f0960000060017e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e00600c7e7e7e7e7e7e7e7e7e7e7e7e0060017f0060017f017f60027f7f0060037f7f7f0002510408657468657265756d08636f6465436f7079000808657468657265756d06726576657274000708657468657265756d0c67657443616c6c56616c7565000508657468657265756d0666696e6973680007030a090002020606010403030503010001060100071102066d656d6f72790200046d61696e00040086030c435f335f6465706c6f7965640061736d0100000001160460000060047e7e7e7e017f60017f017f60027f7f0002130108657468657265756d067265766572740003030504000102020503010001060100071102066d656d6f72790200046d61696e00010a9f0204b30104017e027f037e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b2000a71004ad422086210320032000422088a71004ad84210420022004370000200241086a2004370000200241106a2004370000428001a71004ad4220862105200241186a2005428001422088a71004ad84370000200020002000200010022106200020002000200010022107200741c0006a210820082007490440000b2008200610000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100341107421022002200041107610037221010b20010b0af00309dc0103017e027f057e02404200210020002000200042c00010052101200141c0006a210220022001490440000b20001009210320022003370000200241086a2003370000200241106a2003370000200241186a428001100937000041001002410029000010092104410041086a29000010092105410041106a2900001009210620042005842006410041186a290000100984845045044020002000200020002000200020002000100c0b42f9022107200020002000200020002000200042d3012000200020002007100a20002000200020002000200020002007100b0b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310052105200541c0006a210420042005490440000b0b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100741107421022002200041107610077221010b20010b2201027e02402000a71008ad422086210220022000422088a71008ad8421010b20010b25000240200020012002200310062004200520062007100520082009200a200b100510000b0b1b000240200020012002200310062004200520062007100510030b0b1b000240200020012002200310062004200520062007100510010b0b","wast":"(module +{"contracts":{"A":{"C":{"ewasm":{"wasm":"0061736d0100000001470b6000006000017e6000017f60017e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e00600c7e7e7e7e7e7e7e7e7e7e7e7e0060017f0060017f017f60027f7f0060037f7f7f00026e0508657468657265756d08636f6465436f7079000a08657468657265756d06726576657274000908657468657265756d0c67657443616c6c56616c7565000708657468657265756d0666696e697368000908657468657265756d1167657452657475726e4461746153697a650002030b0a0004040808030601050505030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e000500be030c435f335f6465706c6f7965640061736d01000000011a056000006000017f60047e7e7e7e017f60017f017f60027f7f0002300208657468657265756d06726576657274000408657468657265756d1167657452657475726e4461746153697a65000103060500020203030503010001060100071102066d656d6f72790200046d61696e00020ab50205a20103017e027f057e02404200210020002000200042c00010032101200141c0006a210220022001490440000b2000a71006ad422086210320032000422088a71006ad84210420022004370000200241086a2004370000200241106a2004370000428001a71006ad4220862105200241186a2005428001422088a71006ad843700001001ad21061001ad2107200020002000200710042000200020002006100310000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310032105200541c0006a210420042005490440000b0b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100541107421022002200041107610057221010b20010b0ac6040a970203017e017f157e02404200210020002000200042c000100721012000100a210220012002370000200141086a2002370000200141106a2002370000200141186a428001100a370000410010024100290000100a2103410041086a290000100a2104410041106a290000100a210520032004842005410041186a290000100a8484504504400240100c21062300210723012108230221090b0240100c210a2300210b2301210c2302210d0b200a200b200c200d2006200720082009100e0b42b103210e0240100c210f2300211023012111230221120b200f201020112012200020002000428802200020002000200e100b0240100c21132300211423012115230221160b2013201420152016200020002000200e100d0b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310062105200541c0006a210420042005490440000b0b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100841107421022002200041107610087221010b20010b2201027e02402000a71009ad422086210220022000422088a71009ad8421010b20010b25000240200020012002200310072004200520062007100620082009200a200b100610000b0b1a01047e02401004ad21030b20012400200224012003240220000b1b000240200020012002200310072004200520062007100610030b0b1b000240200020012002200310072004200520062007100610010b0b","wast":"(module ;; custom section for sub-module - ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": 380167268971b84f9fd4e61f1659da4fd304bd6e30ec2dd33d412f3c8203ced7 - ;; (@custom \"C_3_deployed\" \"0061736d0100000001160460000060047e7e7e7e017f60017f017f60027f7f0002130108657468657265756d067265766572740003030504000102020503010001060100071102066d656d6f72790200046d61696e00010a9f0204b30104017e027f037e037f02404200210020002000200042c00010022101200141c0006a210220022001490440000b2000a71004ad422086210320032000422088a71004ad84210420022004370000200241086a2004370000200241106a2004370000428001a71004ad4220862105200241186a2005428001422088a71004ad84370000200020002000200010022106200020002000200010022107200741c0006a210820082007490440000b2008200610000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100341107421022002200041107610037221010b20010b\") + ;; The Keccak-256 hash of the text representation of \"C_3_deployed\": 603ebd2801e128046239523a1467c5ebb690fff231bbffe4074f81586eb77370 + ;; (@custom \"C_3_deployed\" \"0061736d01000000011a056000006000017f60047e7e7e7e017f60017f017f60027f7f0002300208657468657265756d06726576657274000408657468657265756d1167657452657475726e4461746153697a65000103060500020203030503010001060100071102066d656d6f72790200046d61696e00020ab50205a20103017e027f057e02404200210020002000200042c00010032101200141c0006a210220022001490440000b2000a71006ad422086210320032000422088a71006ad84210420022004370000200241086a2004370000200241106a2004370000428001a71006ad4220862105200241186a2005428001422088a71006ad843700001001ad21061001ad2107200020002000200710042000200020002006100310000b0b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b2601027f0240200020012002200310032105200541c0006a210420042005490440000b0b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100541107421022002200041107610057221010b20010b\") (import \"ethereum\" \"codeCopy\" (func $eth.codeCopy (param i32 i32 i32))) (import \"ethereum\" \"revert\" (func $eth.revert (param i32 i32))) (import \"ethereum\" \"getCallValue\" (func $eth.getCallValue (param i32))) (import \"ethereum\" \"finish\" (func $eth.finish (param i32 i32))) + (import \"ethereum\" \"getReturnDataSize\" (func $eth.getReturnDataSize (result i32))) (memory $memory (export \"memory\") 1) (export \"main\" (func $main)) + (global $global_ (mut i64) (i64.const 0)) + (global $global__1 (mut i64) (i64.const 0)) + (global $global__2 (mut i64) (i64.const 0)) (func $main (local $_1 i64) - (local $p i32) - (local $r i32) - (local $_2 i64) + (local $_2 i32) + (local $_3 i64) (local $z1 i64) (local $z2 i64) (local $z3 i64) - (local $_3 i64) + (local $_4 i64) + (local $_5 i64) + (local $_6 i64) + (local $_7 i64) + (local $_8 i64) + (local $_9 i64) + (local $_10 i64) + (local $_11 i64) + (local $_12 i64) + (local $_13 i64) + (local $_14 i64) + (local $_15 i64) + (local $_16 i64) + (local $_17 i64) + (local $_18 i64) + (local $_19 i64) + (local $_20 i64) (block $label_ (local.set $_1 (i64.const 0)) - (local.set $p (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 64))) - (local.set $r (i32.add (local.get $p) (i32.const 64))) - (if (i32.lt_u (local.get $r) (local.get $p)) (then - (unreachable))) - (local.set $_2 (call $bswap64 (local.get $_1))) - (i64.store (local.get $r) (local.get $_2)) - (i64.store (i32.add (local.get $r) (i32.const 8)) (local.get $_2)) - (i64.store (i32.add (local.get $r) (i32.const 16)) (local.get $_2)) - (i64.store (i32.add (local.get $r) (i32.const 24)) (call $bswap64 (i64.const 128))) + (local.set $_2 (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 64))) + (local.set $_3 (call $bswap64 (local.get $_1))) + (i64.store (local.get $_2) (local.get $_3)) + (i64.store (i32.add (local.get $_2) (i32.const 8)) (local.get $_3)) + (i64.store (i32.add (local.get $_2) (i32.const 16)) (local.get $_3)) + (i64.store (i32.add (local.get $_2) (i32.const 24)) (call $bswap64 (i64.const 128))) (call $eth.getCallValue (i32.const 0)) (local.set $z1 (call $bswap64 (i64.load (i32.const 0)))) (local.set $z2 (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 8))))) (local.set $z3 (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 16))))) (if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $z1) (local.get $z2)) (i64.or (local.get $z3) (call $bswap64 (i64.load (i32.add (i32.const 0) (i32.const 24)))))))) (then - (call $revert (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)))) - (local.set $_3 (datasize \"C_3_deployed\")) - (call $codecopy (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (dataoffset \"C_3_deployed\") (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3)) - (call $return (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3)) + (block + (local.set $_4 (call $returndatasize)) + (local.set $_5 (global.get $global_)) + (local.set $_6 (global.get $global__1)) + (local.set $_7 (global.get $global__2)) + + ) + (block + (local.set $_8 (call $returndatasize)) + (local.set $_9 (global.get $global_)) + (local.set $_10 (global.get $global__1)) + (local.set $_11 (global.get $global__2)) + + ) + (call $revert (local.get $_8) (local.get $_9) (local.get $_10) (local.get $_11) (local.get $_4) (local.get $_5) (local.get $_6) (local.get $_7)))) + (local.set $_12 (datasize \"C_3_deployed\")) + (block + (local.set $_13 (call $returndatasize)) + (local.set $_14 (global.get $global_)) + (local.set $_15 (global.get $global__1)) + (local.set $_16 (global.get $global__2)) + + ) + (call $codecopy (local.get $_13) (local.get $_14) (local.get $_15) (local.get $_16) (local.get $_1) (local.get $_1) (local.get $_1) (dataoffset \"C_3_deployed\") (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_12)) + (block + (local.set $_17 (call $returndatasize)) + (local.set $_18 (global.get $global_)) + (local.set $_19 (global.get $global__1)) + (local.set $_20 (global.get $global__2)) + + ) + (call $return (local.get $_17) (local.get $_18) (local.get $_19) (local.get $_20) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_12)) ) ) @@ -48,7 +92,7 @@ (param $x4 i64) (result i32) (local $v i32) - (block $label__1 + (block $label__3 (if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then (unreachable))) (if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then @@ -67,7 +111,7 @@ (result i32) (local $r i32) (local $p i32) - (block $label__2 + (block $label__4 (local.set $p (call $u256_to_i32 (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4))) (local.set $r (i32.add (local.get $p) (i32.const 64))) (if (i32.lt_u (local.get $r) (local.get $p)) (then @@ -81,7 +125,7 @@ (param $x i32) (result i32) (local $y i32) - (block $label__3 + (block $label__5 (local.set $y (i32.or (i32.and (i32.shl (local.get $x) (i32.const 8)) (i32.const 65280)) (i32.and (i32.shr_u (local.get $x) (i32.const 8)) (i32.const 255)))) ) @@ -93,7 +137,7 @@ (result i32) (local $y i32) (local $hi i32) - (block $label__4 + (block $label__6 (local.set $hi (i32.shl (call $bswap16 (local.get $x)) (i32.const 16))) (local.set $y (i32.or (local.get $hi) (call $bswap16 (i32.shr_u (local.get $x) (i32.const 16))))) @@ -106,7 +150,7 @@ (result i64) (local $y i64) (local $hi i64) - (block $label__5 + (block $label__7 (local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (local.get $x)))) (i64.const 32))) (local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (local.get $x) (i64.const 32))))))) @@ -127,11 +171,27 @@ (param $z2 i64) (param $z3 i64) (param $z4 i64) - (block $label__6 + (block $label__8 (call $eth.codeCopy (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) (call $u256_to_i32 (local.get $z1) (local.get $z2) (local.get $z3) (local.get $z4))) ) ) +(func $returndatasize + (result i64) + (local $z1 i64) + (local $z2 i64) + (local $z3 i64) + (local $z4 i64) + (block $label__9 + (local.set $z4 (i64.extend_i32_u (call $eth.getReturnDataSize))) + + ) + (global.set $global_ (local.get $z2)) + (global.set $global__1 (local.get $z3)) + (global.set $global__2 (local.get $z4)) + (local.get $z1) +) + (func $return (param $x1 i64) (param $x2 i64) @@ -141,7 +201,7 @@ (param $y2 i64) (param $y3 i64) (param $y4 i64) - (block $label__7 + (block $label__10 (call $eth.finish (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))) ) ) @@ -155,7 +215,7 @@ (param $y2 i64) (param $y3 i64) (param $y4 i64) - (block $label__8 + (block $label__11 (call $eth.revert (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))) ) ) diff --git a/test/cmdlineTests/standard_yul_optimized/output.json b/test/cmdlineTests/standard_yul_optimized/output.json index 758904e93c07..9c1f1a89e62e 100644 --- a/test/cmdlineTests/standard_yul_optimized/output.json +++ b/test/cmdlineTests/standard_yul_optimized/output.json @@ -1,6 +1,6 @@ {"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":17:18 */ - 0x00 - 0x00 + returndatasize + returndatasize /* \"A\":11:19 */ mload /* \"A\":20:40 */ @@ -12,6 +12,10 @@ } } ","irOptimized":"object \"object\" { - code { { sstore(mload(0), 0) } } + code { + { + sstore(mload(returndatasize()), returndatasize()) + } + } } "}}},"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/viair_subobjects/output b/test/cmdlineTests/viair_subobjects/output index 36019c4b8a94..462735d99026 100644 --- a/test/cmdlineTests/viair_subobjects/output +++ b/test/cmdlineTests/viair_subobjects/output @@ -1,9 +1,9 @@ ======= viair_subobjects/input.sol:C ======= Binary: -60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +60806040523415600d573d3dfd5b600880601a3d39803df350fe60806040523d3dfd Binary of the runtime part: -608060405260006000fd +60806040523d3dfd Optimized IR: /******************************************************* * WARNING * @@ -16,17 +16,20 @@ object "C_3" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_3_deployed"), _1) + return(returndatasize(), _1) } } object "C_3_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } @@ -35,9 +38,9 @@ object "C_3" { ======= viair_subobjects/input.sol:D ======= Binary: -608060405234156100105760006000fd5b61010d80610021600039806000f350fe6080604052600436101515610088576000803560e01c6326121ff0141561008657341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005e5761005d6100cb565b5b50806100e560803980608083f01515610079573d82833e3d82fd5b508061008482610092565bf35b505b60006000fd6100e3565b60006040519050601f19601f830116810181811067ffffffffffffffff821117156100c0576100bf6100cb565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +6080604052341561000e573d3dfd5b6101068061001d3d39803df350fe6080604052600436101515610087573d803560e01c6326121ff01415610085573415610029578081fd5b8060031936011215610039578081fd5b6022806080016080811067ffffffffffffffff8211171561005d5761005c6100ca565b5b50806100e460803980608083f01515610078573d82833e3d82fd5b508061008382610091565bf35b505b60006000fd6100e2565b60006040519050601f19601f830116810181811067ffffffffffffffff821117156100bf576100be6100ca565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600d573d3dfd5b600880601a3d39803df350fe60806040523d3dfd Binary of the runtime part: -6080604052600436101515610088576000803560e01c6326121ff0141561008657341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005e5761005d6100cb565b5b50806100e560803980608083f01515610079573d82833e3d82fd5b508061008482610092565bf35b505b60006000fd6100e3565b60006040519050601f19601f830116810181811067ffffffffffffffff821117156100c0576100bf6100cb565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd +6080604052600436101515610087573d803560e01c6326121ff01415610085573415610029578081fd5b8060031936011215610039578081fd5b6022806080016080811067ffffffffffffffff8211171561005d5761005c6100ca565b5b50806100e460803980608083f01515610078573d82833e3d82fd5b508061008382610091565bf35b505b60006000fd6100e2565b60006040519050601f19601f830116810181811067ffffffffffffffff821117156100bf576100be6100ca565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600d573d3dfd5b600880601a3d39803df350fe60806040523d3dfd Optimized IR: /******************************************************* * WARNING * @@ -50,10 +53,13 @@ object "D_16" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("D_16_deployed") - codecopy(0, dataoffset("D_16_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("D_16_deployed"), _1) + return(returndatasize(), _1) } } object "D_16_deployed" { @@ -62,7 +68,7 @@ object "D_16" { mstore(64, 128) if iszero(lt(calldatasize(), 4)) { - let _1 := 0 + let _1 := returndatasize() if eq(0x26121ff0, shr(224, calldataload(_1))) { if callvalue() { revert(_1, _1) } @@ -99,17 +105,20 @@ object "D_16" { code { { mstore(64, 128) - if callvalue() { revert(0, 0) } + if callvalue() + { + revert(returndatasize(), returndatasize()) + } let _1 := datasize("C_3_deployed") - codecopy(0, dataoffset("C_3_deployed"), _1) - return(0, _1) + codecopy(returndatasize(), dataoffset("C_3_deployed"), _1) + return(returndatasize(), _1) } } object "C_3_deployed" { code { { mstore(64, 128) - revert(0, 0) + revert(returndatasize(), returndatasize()) } } } diff --git a/test/libyul/YulOptimizerTestCommon.cpp b/test/libyul/YulOptimizerTestCommon.cpp index c8305eaa2e86..d4d24787e5f7 100644 --- a/test/libyul/YulOptimizerTestCommon.cpp +++ b/test/libyul/YulOptimizerTestCommon.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -356,7 +357,11 @@ YulOptimizerTestCommon::YulOptimizerTestCommon( FakeUnreachableGenerator fakeUnreachableGenerator; fakeUnreachableGenerator(*m_ast); StackLimitEvader::run(*m_context, *m_object, fakeUnreachableGenerator.fakeUnreachables); - }} + }}, + {"zeroByReturndatasizeReplacer", [&]() { + disambiguate(); + ZeroByReturndatasizeReplacer::run(*m_context, *m_ast); + }}, }; } diff --git a/test/libyul/objectCompiler/long_object_name.yul b/test/libyul/objectCompiler/long_object_name.yul index 322079928559..4ce89c47d737 100644 --- a/test/libyul/objectCompiler/long_object_name.yul +++ b/test/libyul/objectCompiler/long_object_name.yul @@ -13,13 +13,13 @@ object "t" { // /* "source":23:147 */ // dataSize(sub_0) // /* "source":30:31 */ -// 0x00 +// returndatasize // /* "source":23:147 */ // sstore // stop // // sub_0: assembly { // } -// Bytecode: 6000600055fe -// Opcodes: PUSH1 0x0 PUSH1 0x0 SSTORE INVALID +// Bytecode: 60003d55fe +// Opcodes: PUSH1 0x0 RETURNDATASIZE SSTORE INVALID // SourceMappings: 23:124:0:-:0;30:1;23:124 diff --git a/test/libyul/objectCompiler/nested_optimizer.yul b/test/libyul/objectCompiler/nested_optimizer.yul index e4512f03dfc7..7e5b767dbf25 100644 --- a/test/libyul/objectCompiler/nested_optimizer.yul +++ b/test/libyul/objectCompiler/nested_optimizer.yul @@ -19,8 +19,8 @@ object "a" { // ---- // Assembly: // /* "source":48:49 */ -// 0x00 -// 0x00 +// returndatasize +// returndatasize // /* "source":35:50 */ // calldataload // /* "source":107:127 */ @@ -29,13 +29,13 @@ object "a" { // // sub_0: assembly { // /* "source":188:189 */ -// 0x00 -// 0x00 +// returndatasize +// returndatasize // /* "source":175:190 */ // calldataload // /* "source":253:273 */ // sstore // } -// Bytecode: 600060003555fe -// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE INVALID +// Bytecode: 3d3d3555fe +// Opcodes: RETURNDATASIZE RETURNDATASIZE CALLDATALOAD SSTORE INVALID // SourceMappings: 48:1:0:-:0;;35:15;107:20 diff --git a/test/libyul/objectCompiler/simple_optimizer.yul b/test/libyul/objectCompiler/simple_optimizer.yul index 40234a1db56d..ea64b3effd7e 100644 --- a/test/libyul/objectCompiler/simple_optimizer.yul +++ b/test/libyul/objectCompiler/simple_optimizer.yul @@ -9,12 +9,12 @@ // ---- // Assembly: // /* "source":26:27 */ -// 0x00 -// 0x00 +// returndatasize +// returndatasize // /* "source":13:28 */ // calldataload // /* "source":79:99 */ // sstore -// Bytecode: 600060003555 -// Opcodes: PUSH1 0x0 PUSH1 0x0 CALLDATALOAD SSTORE +// Bytecode: 3d3d3555 +// Opcodes: RETURNDATASIZE RETURNDATASIZE CALLDATALOAD SSTORE // SourceMappings: 26:1:0:-:0;;13:15;79:20 diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi2.yul b/test/libyul/yulOptimizerTests/fullSuite/abi2.yul index acef62cc5830..832db69d75e6 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/abi2.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/abi2.yul @@ -1078,9 +1078,12 @@ // { // { // let _1 := mload(1) -// let _2 := mload(0) -// if slt(sub(_1, _2), 64) { revert(0, 0) } -// sstore(0, and(calldataload(_2), sub(shl(160, 1), 1))) +// let _2 := mload(returndatasize()) +// if slt(sub(_1, _2), 64) +// { +// revert(returndatasize(), returndatasize()) +// } +// sstore(returndatasize(), and(calldataload(_2), sub(shl(160, 1), 1))) // let x0, x1, x2, x3, x4 := abi_decode_addresst_uint256t_bytes_calldatat_enum_Operation(mload(7), mload(8)) // sstore(x1, x0) // sstore(x3, x2) diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul index 69dfb946cb81..516f6d7f2367 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul @@ -463,14 +463,14 @@ // // { // { -// let _1 := 0 -// let _2 := mload(_1) +// let _1 := returndatasize() +// let _2 := mload(returndatasize()) // let pos := 0x20 // let length := mload(_2) // mstore(pos, length) // pos := 64 // let srcPtr := add(_2, 0x20) -// let i := _1 +// let i := returndatasize() // for { } lt(i, length) { i := add(i, 1) } // { // let _3 := mload(srcPtr) @@ -489,7 +489,7 @@ // let a, b, c, d := abi_decode_uint256t_uint256t_array_uint256_dynt_array_array_uint256_memory_dyn(mload(0x20), mload(64)) // sstore(a, b) // sstore(c, d) -// sstore(_1, pos) +// sstore(returndatasize(), pos) // } // function abi_decode_array_array_uint256_memory_dyn(offset, end) -> array // { @@ -503,17 +503,26 @@ // dst := add(array, _2) // let src := add(offset, _2) // let _3 := 0x40 -// if gt(add(add(offset, mul(length, _3)), _2), end) { revert(0, 0) } -// let i := 0 +// if gt(add(add(offset, mul(length, _3)), _2), end) +// { +// revert(returndatasize(), returndatasize()) +// } +// let i := returndatasize() // for { } lt(i, length) { i := add(i, 1) } // { -// if iszero(slt(add(src, _1), end)) { revert(0, 0) } +// if iszero(slt(add(src, _1), end)) +// { +// revert(returndatasize(), returndatasize()) +// } // let dst_1 := allocateMemory(_3) // let dst_2 := dst_1 // let src_1 := src // let _4 := add(src, _3) -// if gt(_4, end) { revert(0, 0) } -// let i_1 := 0 +// if gt(_4, end) +// { +// revert(returndatasize(), returndatasize()) +// } +// let i_1 := returndatasize() // for { } lt(i_1, 0x2) { i_1 := add(i_1, 1) } // { // mstore(dst_1, calldataload(src_1)) @@ -552,19 +561,28 @@ // } // value2 := dst_1 // let offset_1 := calldataload(add(headStart, 96)) -// if gt(offset_1, _2) { revert(value3, value3) } +// if gt(offset_1, _2) +// { +// revert(returndatasize(), returndatasize()) +// } // value3 := abi_decode_array_array_uint256_memory_dyn(add(headStart, offset_1), dataEnd) // } // function allocateMemory(size) -> memPtr // { // memPtr := mload(64) // let newFreePtr := add(memPtr, size) -// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { revert(0, 0) } +// if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) +// { +// revert(returndatasize(), returndatasize()) +// } // mstore(64, newFreePtr) // } // function array_allocation_size_array_address_dyn_memory(length) -> size // { -// if gt(length, 0xffffffffffffffff) { revert(size, size) } +// if gt(length, 0xffffffffffffffff) +// { +// revert(returndatasize(), returndatasize()) +// } // size := add(mul(length, 0x20), 0x20) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/and_or_combination.yul b/test/libyul/yulOptimizerTests/fullSuite/and_or_combination.yul index b5f45605498d..2d12c32d3a81 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/and_or_combination.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/and_or_combination.yul @@ -20,6 +20,6 @@ // // { // { -// sstore(sload(0), 0xad9c000000000000823500000000000056ce0000000000002b67) +// sstore(sload(returndatasize()), 0xad9c000000000000823500000000000056ce0000000000002b67) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/aztec.yul b/test/libyul/yulOptimizerTests/fullSuite/aztec.yul index 1076f349a44e..d5baab9a3c48 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/aztec.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/aztec.yul @@ -243,8 +243,8 @@ // let challenge := mod(calldataload(0x44), _2) // if gt(m, n) // { -// mstore(0x00, 404) -// revert(0x00, 0x20) +// mstore(returndatasize(), 404) +// revert(returndatasize(), 0x20) // } // let kn := calldataload(add(calldatasize(), not(191))) // mstore(0x2a0, caller()) @@ -253,7 +253,7 @@ // kn := mulmod(sub(_2, kn), challenge, _2) // hashCommitments(notes, n) // let b := add(0x300, mul(n, _1)) -// let i := 0 +// let i := returndatasize() // for { } lt(i, n) { i := add(i, 0x01) } // { // let _3 := add(calldataload(0x04), mul(i, 0xc0)) @@ -372,12 +372,12 @@ // } // function hashCommitments(notes, n) // { -// let i := 0 +// let i := returndatasize() // for { } lt(i, n) { i := add(i, 0x01) } // { // let _1 := 0x80 // calldatacopy(add(0x300, mul(i, _1)), add(add(notes, mul(i, 0xc0)), 0x60), _1) // } -// mstore(0, keccak256(0x300, mul(n, 0x80))) +// mstore(returndatasize(), keccak256(0x300, mul(n, 0x80))) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/clear_after_if_continue.yul b/test/libyul/yulOptimizerTests/fullSuite/clear_after_if_continue.yul index 71ed36d9794d..6376c4cf4b7a 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/clear_after_if_continue.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/clear_after_if_continue.yul @@ -18,14 +18,17 @@ // { // if y // { -// let _2 := 0 +// let _2 := returndatasize() // revert(_2, _2) // } // } // { // if y { continue } -// sstore(1, 0) +// sstore(1, returndatasize()) +// } +// if y +// { +// revert(returndatasize(), returndatasize()) // } -// if y { revert(0, 0) } // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and.yul b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and.yul index 1abea23e7802..6b6464985e55 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and.yul @@ -11,7 +11,7 @@ // // { // { -// let x := calldataload(0) +// let x := calldataload(returndatasize()) // sstore(shr(248, x), and(shr(4, x), 3855)) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_2.yul b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_2.yul index 513a23aa5066..c20764f79a86 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_2.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_2.yul @@ -22,14 +22,14 @@ // // { // { -// let x := calldataload(0) +// let x := calldataload(returndatasize()) // let b := and(shl(8, x), 15790080) -// sstore(10, 0) +// sstore(10, returndatasize()) // sstore(11, b) // sstore(12, b) -// sstore(13, 0) +// sstore(13, returndatasize()) // sstore(14, and(shl(251, x), shl(255, 1))) -// sstore(0xf, 0) -// sstore(16, 0) +// sstore(0xf, returndatasize()) +// sstore(16, returndatasize()) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_3.yul b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_3.yul index 17de07de7cd7..a8c81e3a2833 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_3.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_3.yul @@ -19,7 +19,7 @@ // // { // { -// let x := calldataload(0) +// let x := calldataload(returndatasize()) // let _1 := shl(8, x) // let _2 := shr(8, x) // sstore(15, x) @@ -27,6 +27,6 @@ // sstore(17, and(_2, sub(shl(248, 1), 16))) // sstore(18, and(_2, sub(shl(244, 1), 1))) // sstore(19, and(_1, sub(shl(252, 1), 256))) -// sstore(20, 0) +// sstore(20, returndatasize()) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_unsplit.yul b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_unsplit.yul index 923a18f4fd91..57df89c50c8c 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_unsplit.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/combine_shift_and_and_unsplit.yul @@ -13,7 +13,7 @@ // // { // { -// let x := calldataload(0) +// let x := calldataload(returndatasize()) // sstore(shr(248, x), and(shr(4, x), 3855)) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/create2_and_mask.yul b/test/libyul/yulOptimizerTests/fullSuite/create2_and_mask.yul index 813c2706e3d5..5c2fbdc144b1 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/create2_and_mask.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/create2_and_mask.yul @@ -14,7 +14,7 @@ // { // { // let _1 := sub(shl(160, 1), 1) -// let _2 := 0 +// let _2 := returndatasize() // let a := and(create2(_2, _2, 0x20, _2), _1) // sstore(a, and(_1, create2(_2, _2, 0x20, _2))) // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/create_and_mask.yul b/test/libyul/yulOptimizerTests/fullSuite/create_and_mask.yul index c89c620bb52d..ad3c66814999 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/create_and_mask.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/create_and_mask.yul @@ -14,7 +14,7 @@ // { // { // let _1 := sub(shl(160, 1), 1) -// let a := and(create(0, 0, 0x20), _1) +// let a := and(create(returndatasize(), returndatasize(), 0x20), _1) // sstore(a, and(_1, create(0, 0, 0x20))) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/devcon_example.yul b/test/libyul/yulOptimizerTests/fullSuite/devcon_example.yul index c5cdf81041b1..52a0a0fcb416 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/devcon_example.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/devcon_example.yul @@ -19,15 +19,15 @@ // // { // { -// let _1 := calldataload(0) -// let sum := 0 +// let _1 := calldataload(returndatasize()) +// let sum := returndatasize() // let length := calldataload(_1) -// let i := sum +// let i := returndatasize() // for { } lt(i, length) { i := add(i, 1) } // { // let _2 := 0x20 // sum := add(sum, calldataload(add(add(_1, mul(i, _2)), _2))) // } -// sstore(0, sum) +// sstore(returndatasize(), sum) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/loopInvariantCodeMotion.yul b/test/libyul/yulOptimizerTests/fullSuite/loopInvariantCodeMotion.yul index 3b30ac4f7f05..234eb5eefe7b 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/loopInvariantCodeMotion.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/loopInvariantCodeMotion.yul @@ -22,16 +22,16 @@ // // { // { -// let _1 := calldataload(0) -// let sum := 0 +// let _1 := calldataload(returndatasize()) +// let sum := returndatasize() // let length := calldataload(_1) -// let i := sum +// let i := returndatasize() // let _2 := calldataload(7) // for { } lt(i, length) { i := add(i, 1) } // { // let _3 := 0x20 // sum := add(sum, add(calldataload(add(add(_1, mul(i, _3)), _3)), _2)) // } -// sstore(0, sum) +// sstore(returndatasize(), sum) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/no_move_loop_orig.yul b/test/libyul/yulOptimizerTests/fullSuite/no_move_loop_orig.yul index f0ee054b9a01..5c89e9f92cf5 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/no_move_loop_orig.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/no_move_loop_orig.yul @@ -18,7 +18,7 @@ // { // for { } iszero(_1) { } // { } -// mstore(192, 0) +// mstore(192, returndatasize()) // } // { if iszero(msize()) { break } } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul b/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul index a0ac5c36d292..61fe36205903 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/remove_redundant_assignments_in_switch.yul @@ -11,7 +11,7 @@ // // { // { -// switch mload(0) +// switch mload(returndatasize()) // case 0 { } // case 1 { } // default { invalid() } diff --git a/test/libyul/yulOptimizerTests/fullSuite/reserved_identifiers.yul b/test/libyul/yulOptimizerTests/fullSuite/reserved_identifiers.yul index 40bcbd64a427..40111c3620b6 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/reserved_identifiers.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/reserved_identifiers.yul @@ -26,7 +26,7 @@ // } // function datasize_(x) -> linkersymbol_ // { -// if calldataload(linkersymbol_) { linkersymbol_ := datasize_(x) } +// if calldataload(returndatasize()) { linkersymbol_ := datasize_(x) } // sstore(linkersymbol_, calldataload(linkersymbol_)) // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/ssaReverse.yul b/test/libyul/yulOptimizerTests/fullSuite/ssaReverse.yul index 38fb86d27b6f..d8cbada3af7b 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/ssaReverse.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/ssaReverse.yul @@ -36,7 +36,7 @@ // // { // { -// let a, b := abi_decode_bytes_calldata(mload(0), mload(1)) +// let a, b := abi_decode_bytes_calldata(mload(returndatasize()), mload(1)) // let a_1, b_1 := abi_decode_bytes_calldata(a, b) // let a_2, b_2 := abi_decode_bytes_calldata(a_1, b_1) // let a_3, b_3 := abi_decode_bytes_calldata(a_2, b_2) @@ -47,10 +47,19 @@ // } // function abi_decode_bytes_calldata(offset, end) -> arrayPos, length // { -// if iszero(slt(add(offset, 0x1f), end)) { revert(arrayPos, arrayPos) } +// if iszero(slt(add(offset, 0x1f), end)) +// { +// revert(returndatasize(), returndatasize()) +// } // length := calldataload(offset) -// if gt(length, 0xffffffffffffffff) { revert(arrayPos, arrayPos) } +// if gt(length, 0xffffffffffffffff) +// { +// revert(returndatasize(), returndatasize()) +// } // arrayPos := add(offset, 0x20) -// if gt(add(add(offset, length), 0x20), end) { revert(0, 0) } +// if gt(add(add(offset, length), 0x20), end) +// { +// revert(returndatasize(), returndatasize()) +// } // } // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/ssaReverseComplex.yul b/test/libyul/yulOptimizerTests/fullSuite/ssaReverseComplex.yul index 4421dd3cdf20..16bc3f0c970a 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/ssaReverseComplex.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/ssaReverseComplex.yul @@ -14,7 +14,7 @@ // // { // { -// let a := mload(0) +// let a := mload(returndatasize()) // let b := mload(1) // if mload(2) // { diff --git a/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul b/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul index b417991c271e..2df75ebd3cb2 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/stack_compressor_msize.yul @@ -47,10 +47,10 @@ // pop(keccak256(gcd(10, 15), or(gt(not(gcd(10, 15)), 1), 1))) // mstore(lt(or(gt(1, or(or(gt(or(or(or(gt(or(gt(_3, _6), 1), _5), _4), _2), 1), 1), _1), 1)), 1), 1), 1) // sstore(not(gcd(10, 15)), 1) -// sstore(0, 0) +// sstore(returndatasize(), returndatasize()) // sstore(2, 1) // extcodecopy(1, msize(), 1, 1) -// sstore(0, 0) +// sstore(returndatasize(), returndatasize()) // sstore(3, 1) // } // function gcd(_a, _b) -> out diff --git a/test/libyul/yulOptimizerTests/fullSuite/switch_inline.yul b/test/libyul/yulOptimizerTests/fullSuite/switch_inline.yul index 65c7512d350d..8328fbb04f66 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/switch_inline.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/switch_inline.yul @@ -9,4 +9,6 @@ // ---- // step: fullSuite // -// { { mstore(9, 0) } } +// { +// { mstore(9, returndatasize()) } +// } diff --git a/test/libyul/yulOptimizerTests/fullSuite/switch_inline_match_default.yul b/test/libyul/yulOptimizerTests/fullSuite/switch_inline_match_default.yul index cff8bd755c1d..dd1d890f8e2c 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/switch_inline_match_default.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/switch_inline_match_default.yul @@ -10,4 +10,6 @@ // ---- // step: fullSuite // -// { { mstore(10, 0) } } +// { +// { mstore(10, returndatasize()) } +// } diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul index b7f0b4afbf80..c541abf00e01 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner.yul @@ -20,8 +20,8 @@ // { // { // let out1, out2 := foo(sload(32)) -// sstore(0, out1) -// sstore(0, out2) +// sstore(returndatasize(), out1) +// sstore(returndatasize(), out2) // let out1_1, out2_1 := foo(sload(8)) // } // function foo(b) -> out1, out2 diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul index b531842dbd6d..b177939a2a86 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_loop.yul @@ -18,17 +18,17 @@ // { // { // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // } // function f() // { // let b := 10 -// let _1 := 0 -// let a := calldataload(_1) +// let _1 := returndatasize() +// let a := calldataload(returndatasize()) // let _2 := iszero(a) // for { } iszero(b) { b := add(b, not(0)) } // { diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul index 69b4517eb365..7e5962059d7a 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_recursion.yul @@ -15,7 +15,7 @@ // { // { // let x, y, z := f() -// sstore(0, x) +// sstore(returndatasize(), x) // sstore(1, y) // sstore(1, z) // } diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul index 14f0137cb162..0e88a216cae6 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_return.yul @@ -22,9 +22,9 @@ // { // { // let out1, out2 := foo(sload(32)) -// sstore(0, out1) -// sstore(0, out2) -// sstore(0, 0) +// sstore(returndatasize(), out1) +// sstore(returndatasize(), out2) +// sstore(returndatasize(), returndatasize()) // let out1_1, out2_1 := foo(sload(8)) // } // function foo(b) -> out1, out2 diff --git a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul index 531b1a6ce992..810fffb1ee4e 100644 --- a/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul +++ b/test/libyul/yulOptimizerTests/fullSuite/unusedFunctionParameterPruner_simple.yul @@ -16,16 +16,16 @@ // { // { // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // f() -// sstore(0, 1) +// sstore(returndatasize(), 1) // } // function f() // { -// let a := calldataload(0) -// mstore(a, 0) +// let a := calldataload(returndatasize()) +// mstore(a, returndatasize()) // if iszero(a) { leave } // } // } diff --git a/test/yulPhaser/Chromosome.cpp b/test/yulPhaser/Chromosome.cpp index ac4c49055545..6ec5dead7486 100644 --- a/test/yulPhaser/Chromosome.cpp +++ b/test/yulPhaser/Chromosome.cpp @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(output_operator_should_create_concise_and_unambiguous_strin BOOST_TEST(chromosome.length() == allSteps.size()); BOOST_TEST(chromosome.optimisationSteps() == allSteps); - BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighTLMRrmVatpud"); + BOOST_TEST(toString(chromosome) == "flcCUnDvejsxIOoighTLMRrmVatpudz"); } BOOST_AUTO_TEST_CASE(optimisationSteps_should_translate_chromosomes_genes_to_optimisation_step_names)