solidity/test/libsolidity/semanticTests/viaYul/detect_div_overflow.sol

28 lines
914 B
Solidity
Raw Normal View History

2019-05-23 14:12:32 +00:00
contract C {
function f(uint a, uint b) public pure returns (uint x) {
x = a / b;
}
function g(int8 a, int8 b) public pure returns (int8 x) {
x = a / b;
}
function h(uint256 a, uint256 b) public pure returns (uint256 x) {
x = a / b;
}
}
// ====
2020-09-15 14:16:30 +00:00
// compileViaYul: also
2019-05-23 14:12:32 +00:00
// ----
// f(uint256,uint256): 10, 3 -> 3
2020-10-13 11:28:39 +00:00
// f(uint256,uint256): 1, 0 -> FAILURE, hex"4e487b71", 0x12
// f(uint256,uint256): 0, 0 -> FAILURE, hex"4e487b71", 0x12
2019-05-23 14:12:32 +00:00
// f(uint256,uint256): 0, 1 -> 0
// g(int8,int8): -10, 3 -> -3
// g(int8,int8): -10, -3 -> 3
2020-10-13 11:28:39 +00:00
// g(int8,int8): -10, 0 -> FAILURE, hex"4e487b71", 0x12
2019-05-23 14:12:32 +00:00
// g(int8,int8): -128, 1 -> -128
// g(int8,int8): -128, -2 -> 64
// g(int8,int8): -128, 2 -> -64
2020-10-13 11:28:39 +00:00
// g(int8,int8): -128, -1 -> FAILURE, hex"4e487b71", 0x11
2019-05-23 14:12:32 +00:00
// g(int8,int8): -127, -1 -> 127
// h(uint256,uint256): 0x8000000000000000000000000000000000000000000000000000000000000000, -1 -> 0