mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Cleanup tests for Sol->Yul arithmetic and comparison.
This commit is contained in:
parent
4d739b16a4
commit
28d25afab1
@ -0,0 +1,65 @@
|
||||
contract C {
|
||||
function add() public pure returns (uint8, uint8) {
|
||||
uint8 x; uint8 y = 0;
|
||||
assembly { x := 0x0101 }
|
||||
return (x + y, y + x);
|
||||
}
|
||||
function sub() public pure returns (uint8, uint8) {
|
||||
uint8 x; uint8 y = 1;
|
||||
assembly { x := 0x0101 }
|
||||
return (x - y, y - x);
|
||||
}
|
||||
function mul() public pure returns (uint8, uint8) {
|
||||
uint8 x; uint8 y = 1;
|
||||
assembly { x := 0x0101 }
|
||||
return (x * y, y * x);
|
||||
}
|
||||
function div() public pure returns (uint8, uint8) {
|
||||
uint8 x; uint8 y = 1;
|
||||
assembly { x := 0x0101 }
|
||||
return (x / y, y / x);
|
||||
}
|
||||
function mod() public pure returns (uint8, uint8) {
|
||||
uint8 x; uint8 y = 2;
|
||||
assembly { x := 0x0101 }
|
||||
return (x % y, y % x);
|
||||
}
|
||||
function inc_pre() public pure returns (uint8) {
|
||||
uint8 x;
|
||||
assembly { x := 0x0100 }
|
||||
return ++x;
|
||||
}
|
||||
function inc_post() public pure returns (uint8) {
|
||||
uint8 x;
|
||||
assembly { x := 0x0100 }
|
||||
return x++;
|
||||
}
|
||||
function dec_pre() public pure returns (uint8) {
|
||||
uint8 x;
|
||||
assembly { x := not(0xFF) }
|
||||
return --x;
|
||||
}
|
||||
function dec_post() public pure returns (uint8) {
|
||||
uint8 x;
|
||||
assembly { x := not(0xFF) }
|
||||
return x--;
|
||||
}
|
||||
function neg() public pure returns (int8) {
|
||||
int8 x;
|
||||
assembly { x := 0x80 }
|
||||
return -x;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// add() -> 1, 1
|
||||
// sub() -> 0, 0
|
||||
// mul() -> 1, 1
|
||||
// div() -> 1, 1
|
||||
// mod() -> 1, 0
|
||||
// inc_pre() -> 1
|
||||
// inc_post() -> 0
|
||||
// dec_pre() -> FAILURE
|
||||
// dec_post() -> FAILURE
|
||||
// neg() -> FAILURE
|
41
test/libsolidity/semanticTests/viaYul/cleanup/comparison.sol
Normal file
41
test/libsolidity/semanticTests/viaYul/cleanup/comparison.sol
Normal file
@ -0,0 +1,41 @@
|
||||
contract C {
|
||||
function eq() public pure returns (bool) {
|
||||
uint8 x = 1; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x == y);
|
||||
}
|
||||
function neq() public pure returns (bool) {
|
||||
uint8 x = 1; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x != y);
|
||||
}
|
||||
function geq() public pure returns (bool) {
|
||||
uint8 x = 1; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x >= y);
|
||||
}
|
||||
function leq() public pure returns (bool) {
|
||||
uint8 x = 2; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x <= y);
|
||||
}
|
||||
function gt() public pure returns (bool) {
|
||||
uint8 x = 2; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x > y);
|
||||
}
|
||||
function lt() public pure returns (bool) {
|
||||
uint8 x = 1; uint8 y;
|
||||
assembly { y := 0x0101 }
|
||||
return (x < y);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// eq() -> true
|
||||
// neq() -> false
|
||||
// geq() -> true
|
||||
// leq() -> false
|
||||
// gt() -> true
|
||||
// lt() -> false
|
Loading…
Reference in New Issue
Block a user