diff --git a/test/libsolidity/semanticTests/dirty_calldata_bytes.sol b/test/libsolidity/semanticTests/dirty_calldata_bytes.sol new file mode 100644 index 000000000..05a3793f6 --- /dev/null +++ b/test/libsolidity/semanticTests/dirty_calldata_bytes.sol @@ -0,0 +1,12 @@ +contract C { + function f(bytes calldata b) public returns (bool correct) { + byte a = b[3]; + uint r; + assembly { + r := a + } + correct = r == (0x64 << 248); + } +} +// ---- +// f(bytes): 0x20, 0x04, "dead" -> true \ No newline at end of file diff --git a/test/libsolidity/semanticTests/dirty_calldata_dynamic_array.sol b/test/libsolidity/semanticTests/dirty_calldata_dynamic_array.sol new file mode 100644 index 000000000..1c9d7db30 --- /dev/null +++ b/test/libsolidity/semanticTests/dirty_calldata_dynamic_array.sol @@ -0,0 +1,12 @@ +contract C { + function f(int16[] calldata a) external returns (bool correct) { + uint32 x = uint32(a[1]); + uint r; + assembly { + r := x + } + correct = r == 0x7fff; + } +} +// ---- +// f(int16[]): 0x20, 0x02, 0x7fff, 0x7fff -> true \ No newline at end of file diff --git a/test/libsolidity/semanticTests/dirty_memory_bytes_to_storgage_copy.sol b/test/libsolidity/semanticTests/dirty_memory_bytes_to_storgage_copy.sol new file mode 100644 index 000000000..8fc6c33ec --- /dev/null +++ b/test/libsolidity/semanticTests/dirty_memory_bytes_to_storgage_copy.sol @@ -0,0 +1,16 @@ +contract C { + bytes x; + function f() public returns (uint r) { + bytes memory m = "tmp"; + assembly { + mstore(m, 8) + mstore(add(m, 32), "deadbeef15dead") + } + x = m; + assembly { + r := sload(x_slot) + } + } +} +// ---- +// f() -> 0x6465616462656566313564656164000000000000000000000000000000000010 diff --git a/test/libsolidity/semanticTests/viaYul/dirty_calldata_struct.sol b/test/libsolidity/semanticTests/viaYul/dirty_calldata_struct.sol new file mode 100644 index 000000000..633fc45c6 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_calldata_struct.sol @@ -0,0 +1,18 @@ +pragma experimental ABIEncoderV2; +contract C { + struct S { + uint16[] m; + } + function f(S calldata s) public pure returns (bool correct) { + int8 x = int8(s.m[0]); + uint r; + assembly { + r := x + } + correct = r == 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80; + } +} +// ==== +// compileViaYul: true +// ---- +// f((uint16[])): 0x20, 0x20, 0x01, 0x0180 -> true diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_dynamic_array.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_dynamic_array.sol new file mode 100644 index 000000000..36a253b02 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_memory_dynamic_array.sol @@ -0,0 +1,18 @@ +contract C { + function f() public pure returns (bool correct) { + uint8[] memory m = new uint8[](1); + assembly { + mstore(add(m, 32), 258) + } + uint8 x = m[0]; + uint r; + assembly { + r := x + } + correct = (m[0] == 0x02) && (r == 0x02); + } +} +// ==== +// compileViaYul: true +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_int32.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_int32.sol new file mode 100644 index 000000000..f4f0525bd --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_memory_int32.sol @@ -0,0 +1,18 @@ +contract C { + function f() public pure returns (bool correct) { + uint256[1] memory m; + assembly { + mstore(m, 0xdeadbeef15dead) + } + int32 x = int32(m[0]); + uint r; + assembly { + r := x + } + correct = (m[0] == 0xdeadbeef15dead) && (r == (((2 ** 224 - 1) << 32) | 0xef15dead)); + } +} +// ==== +// compileViaYul: true +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_read.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_read.sol deleted file mode 100644 index d03aa489f..000000000 --- a/test/libsolidity/semanticTests/viaYul/dirty_memory_read.sol +++ /dev/null @@ -1,15 +0,0 @@ -contract C { - function f() public pure returns (uint8 x, bool a, bool b) { - uint8[1] memory m; - assembly { - mstore(m, 257) - } - x = m[0]; - a = (m[0] == 0x01); - b = (m[0] == 0x0101); - } -} -// ==== -// compileViaYul: also -// ---- -// f() -> 1, true, false diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_static_array.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_static_array.sol new file mode 100644 index 000000000..4742bae2d --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_memory_static_array.sol @@ -0,0 +1,18 @@ +contract C { + function f() public pure returns (bool correct) { + uint8[1] memory m; + assembly { + mstore(m, 257) + } + uint8 x = m[0]; + uint r; + assembly { + r := x + } + correct = (m[0] == 0x01) && (r == 0x01); + } +} +// ==== +// compileViaYul: true +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_struct.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_struct.sol new file mode 100644 index 000000000..411cbe069 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_memory_struct.sol @@ -0,0 +1,22 @@ +contract C { + struct S { + uint8[] m; + } + function f() public pure returns (bool correct) { + S memory s; + s.m = new uint8[](1); + assembly { + mstore(add(s, 64), 257) + } + uint8 x = s.m[0]; + uint r; + assembly { + r := x + } + correct = r == 0x01; + } +} +// ==== +// compileViaYul: true +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/dirty_memory_uint32.sol b/test/libsolidity/semanticTests/viaYul/dirty_memory_uint32.sol new file mode 100644 index 000000000..a23a566c5 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/dirty_memory_uint32.sol @@ -0,0 +1,18 @@ +contract C { + function f() public pure returns (bool correct) { + uint256[1] memory m; + assembly { + mstore(m, 0xdeadbeef15dead) + } + uint32 x = uint32(m[0]); + uint r; + assembly { + r := x + } + correct = (r == 0xef15dead) && (m[0] == 0xdeadbeef15dead); + } +} +// ==== +// compileViaYul: true +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes.sol b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes.sol new file mode 100644 index 000000000..ea0112fe5 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes.sol @@ -0,0 +1,18 @@ +contract C { + bytes b; + function f() public returns (bool correct) { + assembly { + sstore(b_slot, or("deadbeef", 0x08)) + } + byte s = b[3]; + uint r; + assembly { + r := s + } + correct = r == (0x64 << 248); + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes_long.sol b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes_long.sol new file mode 100644 index 000000000..9cb01d63a --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_bytes_long.sol @@ -0,0 +1,20 @@ +contract C { + bytes b; + function f() public returns (bool correct) { + assembly { + sstore(b_slot, 0x41) + mstore(0, b_slot) + sstore(keccak256(0, 0x20), "deadbeefdeadbeefdeadbeefdeadbeef") + } + byte s = b[31]; + uint r; + assembly { + r := s + } + correct = r == (0x66 << 248); + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> true \ No newline at end of file diff --git a/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_dynamic_array.sol b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_dynamic_array.sol new file mode 100644 index 000000000..bc886b93d --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_dynamic_array.sol @@ -0,0 +1,20 @@ +contract C { + uint8[] s; + function f() public returns (bool correct) { + s.push(); + assembly { + mstore(0, s_slot) + sstore(keccak256(0, 0x20), 257) + } + uint8 x = s[0]; + uint r; + assembly { + r := x + } + correct = (s[0] == 0x01) && (r == 0x01); + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_static_array.sol b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_static_array.sol new file mode 100644 index 000000000..7d7298fee --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_static_array.sol @@ -0,0 +1,18 @@ +contract C { + uint8[1] s; + function f() public returns (bool correct) { + assembly { + sstore(s_slot, 257) + } + uint8 x = s[0]; + uint r; + assembly { + r := x + } + correct = (s[0] == 0x01) && (r == 0x01); + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> true diff --git a/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_struct.sol b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_struct.sol new file mode 100644 index 000000000..1cf19c5be --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/storage/dirty_storage_struct.sol @@ -0,0 +1,23 @@ +contract C { + struct S { + uint8[] m; + } + S s; + function f() public returns (bool correct) { + s.m.push(); + assembly { + mstore(0, s_slot) + sstore(keccak256(0, 0x20), 257) + } + uint8 x = s.m[0]; + uint r; + assembly { + r := x + } + correct = r == 0x01; + } +} +// ==== +// compileViaYul: also +// ---- +// f() -> true