diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 65f519a9b..d7c095a1f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4427,27 +4427,6 @@ BOOST_AUTO_TEST_CASE(shift_bytes) ABI_CHECK(callContractFunction("right(bytes20,uint8)", "12345678901234567890", 8 * 8), encodeArgs(string(8, 0) + "123456789012")); } -BOOST_AUTO_TEST_CASE(shift_bytes_cleanup) -{ - char const* sourceCode = R"( - contract C { - function left(uint8 y) public returns (bytes20) { - bytes20 x; - assembly { x := "12345678901234567890abcde" } - return x << y; - } - function right(uint8 y) public returns (bytes20) { - bytes20 x; - assembly { x := "12345678901234567890abcde" } - return x >> y; - } - } - )"; - compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("left(uint8)", 8 * 8), encodeArgs("901234567890" + string(8, 0))); - ABI_CHECK(callContractFunction("right(uint8)", 8 * 8), encodeArgs(string(8, 0) + "123456789012")); -} - BOOST_AUTO_TEST_CASE(contracts_separated_with_comment) { char const* sourceCode = R"( diff --git a/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup.sol b/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup.sol new file mode 100644 index 000000000..e8f7d0747 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup.sol @@ -0,0 +1,19 @@ +contract C { + function l(uint8 y) public returns (bytes20) { + bytes20 x; + assembly { x := "12345678901234567890abcde" } + // When compiling via IR, `x` is truncated before applying + // the operation. + return x << y; + } + function r(uint8 y) public returns (bytes20) { + bytes20 x; + assembly { x := "12345678901234567890abcde" } + return x >> y; + } +} +// ==== +// compileViaYul: false +// ---- +// l(uint8): 64 -> 0x3930313233343536373839300000000000000000000000000000000000000000 +// r(uint8): 64 -> 0x313233343536373839303132000000000000000000000000 diff --git a/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup_viaYul.sol b/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup_viaYul.sol new file mode 100644 index 000000000..ca98c7cf5 --- /dev/null +++ b/test/libsolidity/semanticTests/operators/shifts/shift_bytes_cleanup_viaYul.sol @@ -0,0 +1,19 @@ +contract C { + function l(uint8 y) public returns (bytes20) { + bytes20 x; + assembly { x := "12345678901234567890abcde" } + // When compiling via IR, `x` is truncated before applying + // the operation. + return x << y; + } + function r(uint8 y) public returns (bytes20) { + bytes20 x; + assembly { x := "12345678901234567890abcde" } + return x >> y; + } +} +// ==== +// compileViaYul: true +// ---- +// l(uint8): 64 -> 0x3930313233343536373839306162636465000000000000000000000000000000 +// r(uint8): 64 -> 0x313233343536373839303132000000000000000000000000