Overflow-checked addition.

This commit is contained in:
chriseth
2019-04-11 15:45:14 +02:00
committed by Mathias Baumann
parent 826f2d9084
commit 18ab8aeb85
14 changed files with 309 additions and 8 deletions
@@ -0,0 +1,18 @@
contract C {
function f(uint a, uint b) public pure returns (uint x) {
x = a + b;
}
function g(uint8 a, uint8 b) public pure returns (uint8 x) {
x = a + b;
}
}
// ====
// compileViaYul: true
// ----
// f(uint256,uint256): 5, 6 -> 11
// f(uint256,uint256): -2, 1 -> -1
// f(uint256,uint256): -2, 2 -> FAILURE
// f(uint256,uint256): 2, -2 -> FAILURE
// g(uint8,uint8): 128, 64 -> 192
// g(uint8,uint8): 128, 127 -> 255
// g(uint8,uint8): 128, 128 -> FAILURE
@@ -0,0 +1,10 @@
contract C {
function f(address a) public pure returns (address x) {
address b = a;
x = b;
}
}
// ====
// compileViaYul: true
// ----
// f(address): 0x1234 -> 0x1234
@@ -0,0 +1,10 @@
contract C {
function f(uint a) public pure returns (uint x) {
uint b = a;
x = b;
}
}
// ====
// compileViaYul: true
// ----
// f(uint256): 6 -> 6
@@ -0,0 +1,10 @@
contract C {
function f(bool a) public pure returns (bool x) {
bool b = a;
x = b;
}
}
// ====
// compileViaYul: true
// ----
// f(bool): true -> true
@@ -0,0 +1,10 @@
contract C {
function f(uint a, uint b) public pure returns (uint x, uint y) {
x = a;
y = b;
}
}
// ====
// compileViaYul: true
// ----
// f(uint256,uint256): 5, 6 -> 5, 6