Skip to content

Commit f66d1dd

Browse files
committed
fix(llvm): keep the panics of div, mod and constant indexing
1 parent 2bf6cd1 commit f66d1dd

4 files changed

Lines changed: 171 additions & 1 deletion

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//! { "cases": [ {
2+
//! "name": "storage",
3+
//! "inputs": [
4+
//! {
5+
//! "method": "inStorage",
6+
//! "calldata": []
7+
//! }
8+
//! ],
9+
//! "expected": {
10+
//! "return_data": [
11+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
12+
//! "0x0000003200000000000000000000000000000000000000000000000000000000"
13+
//! ],
14+
//! "exception": true
15+
//! }
16+
//! }, {
17+
//! "name": "storage_length",
18+
//! "inputs": [
19+
//! {
20+
//! "method": "inStorageByLength",
21+
//! "calldata": []
22+
//! }
23+
//! ],
24+
//! "expected": {
25+
//! "return_data": [
26+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
27+
//! "0x0000003200000000000000000000000000000000000000000000000000000000"
28+
//! ],
29+
//! "exception": true
30+
//! }
31+
//! }, {
32+
//! "name": "memory",
33+
//! "inputs": [
34+
//! {
35+
//! "method": "inMemory",
36+
//! "calldata": []
37+
//! }
38+
//! ],
39+
//! "expected": {
40+
//! "return_data": [
41+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
42+
//! "0x0000003200000000000000000000000000000000000000000000000000000000"
43+
//! ],
44+
//! "exception": true
45+
//! }
46+
//! }, {
47+
//! "name": "calldata",
48+
//! "inputs": [
49+
//! {
50+
//! "method": "inCalldata",
51+
//! "calldata": [
52+
//! "1", "2", "3"
53+
//! ]
54+
//! }
55+
//! ],
56+
//! "expected": {
57+
//! "return_data": [
58+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
59+
//! "0x0000003200000000000000000000000000000000000000000000000000000000"
60+
//! ],
61+
//! "exception": true
62+
//! }
63+
//! } ] }
64+
65+
// SPDX-License-Identifier: MIT
66+
67+
pragma solidity >=0.8.0;
68+
69+
contract Test {
70+
uint256 constant INDEX = 3;
71+
72+
uint256[3] array;
73+
uint256 guard = 7;
74+
75+
function inStorage() public returns(uint256) {
76+
array[INDEX] = 99;
77+
return guard;
78+
}
79+
80+
function inStorageByLength() public returns(uint256) {
81+
array[array.length] = 99;
82+
return guard;
83+
}
84+
85+
function inMemory() public pure returns(uint256) {
86+
uint256[3] memory data;
87+
return data[INDEX];
88+
}
89+
90+
function inCalldata(uint256[3] calldata data) public pure returns(uint256) {
91+
return data[INDEX];
92+
}
93+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! { "cases": [ {
2+
//! "name": "remainder",
3+
//! "inputs": [
4+
//! {
5+
//! "method": "remainder",
6+
//! "calldata": [
7+
//! "5", "0"
8+
//! ]
9+
//! }
10+
//! ],
11+
//! "expected": {
12+
//! "return_data": [
13+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
14+
//! "0x0000001200000000000000000000000000000000000000000000000000000000"
15+
//! ],
16+
//! "exception": true
17+
//! }
18+
//! }, {
19+
//! "name": "unchecked_division",
20+
//! "inputs": [
21+
//! {
22+
//! "method": "uncheckedDivision",
23+
//! "calldata": [
24+
//! "5", "0"
25+
//! ]
26+
//! }
27+
//! ],
28+
//! "expected": {
29+
//! "return_data": [
30+
//! "0x4E487B7100000000000000000000000000000000000000000000000000000000",
31+
//! "0x0000001200000000000000000000000000000000000000000000000000000000"
32+
//! ],
33+
//! "exception": true
34+
//! }
35+
//! } ] }
36+
37+
// SPDX-License-Identifier: MIT
38+
39+
pragma solidity >=0.8.0;
40+
41+
contract Test {
42+
function remainder(uint256 a, uint256 b) public pure returns(uint256) {
43+
a % b;
44+
return 1;
45+
}
46+
47+
function uncheckedDivision(uint256 a, uint256 b) public pure returns(uint256) {
48+
unchecked {
49+
a / b;
50+
}
51+
return 1;
52+
}
53+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! { "cases": [ {
2+
//! "name": "default",
3+
//! "inputs": [
4+
//! {
5+
//! "method": "main",
6+
//! "calldata": [
7+
//! "0x1122334455667788990011223344556677889900112233445566778899001122", "256"
8+
//! ]
9+
//! }
10+
//! ],
11+
//! "expected": [
12+
//! "0x1100000000000000000000000000000000000000000000000000000000000000"
13+
//! ]
14+
//! } ] }
15+
16+
// SPDX-License-Identifier: MIT
17+
18+
pragma solidity >=0.8.0;
19+
20+
contract Test {
21+
function main(bytes32 value, uint256 index) public pure returns(bytes1) {
22+
return value[uint8(index)];
23+
}
24+
}

0 commit comments

Comments
 (0)