Merge pull request #8858 from ethereum/fix-8857

Add more tests for yul cleanup codegen
This commit is contained in:
chriseth 2020-06-15 17:18:50 +02:00 committed by GitHub
commit cc23794575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 251 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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