mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Overflow-checked addition.
This commit is contained in:
committed by
Mathias Baumann
parent
826f2d9084
commit
18ab8aeb85
@@ -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
|
||||
Reference in New Issue
Block a user