mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8983 from ethereum/develop
Merge develop into breaking.
This commit is contained in:
@@ -34,6 +34,7 @@ set(libsolutil_sources
|
||||
libsolutil/IterateReplacing.cpp
|
||||
libsolutil/JSON.cpp
|
||||
libsolutil/Keccak256.cpp
|
||||
libsolutil/LazyInit.cpp
|
||||
libsolutil/StringUtils.cpp
|
||||
libsolutil/SwarmHash.cpp
|
||||
libsolutil/UTF8.cpp
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
--optimize --asm --metadata-hash none
|
||||
@@ -0,0 +1,11 @@
|
||||
Warning: Statement has no effect.
|
||||
--> optimizer_BlockDeDuplicator/input.sol:7:27:
|
||||
|
|
||||
7 | function f() public { true ? 1 : 3;}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
Warning: Function state mutability can be restricted to pure
|
||||
--> optimizer_BlockDeDuplicator/input.sol:7:5:
|
||||
|
|
||||
7 | function f() public { true ? 1 : 3;}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
|
||||
contract C {
|
||||
function fun_x() public {}
|
||||
function fun_() public {}
|
||||
function f() public { true ? 1 : 3;}
|
||||
function() r = true ? fun_x : f;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
|
||||
======= optimizer_BlockDeDuplicator/input.sol:C =======
|
||||
EVM assembly:
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
mstore(0x40, 0x80)
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":179:210 function() r = true ? fun_x : f */
|
||||
0x00
|
||||
dup1
|
||||
sload
|
||||
not(sub(shl(0x40, 0x01), 0x01))
|
||||
and
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":201:206 fun_x */
|
||||
or(tag_0_7, shl(0x20, tag_4))
|
||||
sub(shl(0x40, 0x01), 0x01)
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":179:210 function() r = true ? fun_x : f */
|
||||
and
|
||||
or
|
||||
swap1
|
||||
sstore
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
callvalue
|
||||
/* "--CODEGEN--":2:4 */
|
||||
dup1
|
||||
iszero
|
||||
tag_5
|
||||
jumpi
|
||||
/* "--CODEGEN--":27:28 */
|
||||
0x00
|
||||
/* "--CODEGEN--":24:25 */
|
||||
dup1
|
||||
/* "--CODEGEN--":17:29 */
|
||||
revert
|
||||
/* "--CODEGEN--":2:4 */
|
||||
tag_5:
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
pop
|
||||
jump(tag_6)
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":77:103 function fun_x() public {} */
|
||||
tag_4:
|
||||
jump // out
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
tag_6:
|
||||
dataSize(sub_0)
|
||||
dup1
|
||||
dataOffset(sub_0)
|
||||
0x00
|
||||
codecopy
|
||||
0x00
|
||||
return
|
||||
stop
|
||||
|
||||
sub_0: assembly {
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
mstore(0x40, 0x80)
|
||||
callvalue
|
||||
/* "--CODEGEN--":5:14 */
|
||||
dup1
|
||||
/* "--CODEGEN--":2:4 */
|
||||
iszero
|
||||
tag_1
|
||||
jumpi
|
||||
/* "--CODEGEN--":27:28 */
|
||||
0x00
|
||||
/* "--CODEGEN--":24:25 */
|
||||
dup1
|
||||
/* "--CODEGEN--":17:29 */
|
||||
revert
|
||||
/* "--CODEGEN--":2:4 */
|
||||
tag_1:
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */
|
||||
pop
|
||||
jumpi(tag_2, lt(calldatasize, 0x04))
|
||||
shr(0xe0, calldataload(0x00))
|
||||
dup1
|
||||
0x26121ff0
|
||||
eq
|
||||
tag_3
|
||||
jumpi
|
||||
dup1
|
||||
0x2e1fb2bc
|
||||
eq
|
||||
tag_3
|
||||
jumpi
|
||||
dup1
|
||||
0x4753a67d
|
||||
eq
|
||||
tag_3
|
||||
jumpi
|
||||
tag_2:
|
||||
/* "--CODEGEN--":12:13 */
|
||||
0x00
|
||||
/* "--CODEGEN--":9:10 */
|
||||
dup1
|
||||
/* "--CODEGEN--":2:14 */
|
||||
revert
|
||||
/* "optimizer_BlockDeDuplicator/input.sol":138:174 function f() public { true ? 1 : 3;} */
|
||||
tag_3:
|
||||
tag_6
|
||||
tag_7
|
||||
jump // in
|
||||
tag_6:
|
||||
stop
|
||||
tag_7:
|
||||
jump // out
|
||||
|
||||
auxdata: AUXDATA REMOVED
|
||||
}
|
||||
@@ -22,7 +22,7 @@ sub_0: assembly {
|
||||
/* \"A\":137:149 */
|
||||
revert
|
||||
}
|
||||
","bytecode":{"linkReferences":{},"object":"bytecode removed","opcodes":"opcodes removed","sourceMap":"sourceMap removed"}},"ir":"object \"NamedObject\" {
|
||||
","bytecode":{"linkReferences":{},"object":"bytecode removed","opcodes":"opcodes removed","sourceMap":"sourceMap removed"},"deployedBytecode":{"linkReferences":{},"object":"bytecode removed","opcodes":"opcodes removed","sourceMap":"sourceMap removed"}},"ir":"object \"NamedObject\" {
|
||||
code {
|
||||
let x := dataoffset(\"DataName\")
|
||||
sstore(add(x, 0), 0)
|
||||
|
||||
@@ -24,9 +24,12 @@
|
||||
#include <test/contracts/ContractInterface.h>
|
||||
#include <test/EVMHost.h>
|
||||
|
||||
#include <libsolutil/LazyInit.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
@@ -211,17 +214,18 @@ contract GlobalRegistrar is Registrar, AuctionSystem {
|
||||
}
|
||||
)DELIMITER";
|
||||
|
||||
static unique_ptr<bytes> s_compiledRegistrar;
|
||||
static LazyInit<bytes> s_compiledRegistrar;
|
||||
|
||||
class AuctionRegistrarTestFramework: public SolidityExecutionFramework
|
||||
{
|
||||
protected:
|
||||
void deployRegistrar()
|
||||
{
|
||||
if (!s_compiledRegistrar)
|
||||
s_compiledRegistrar = make_unique<bytes>(compileContract(registrarCode, "GlobalRegistrar"));
|
||||
bytes const& compiled = s_compiledRegistrar.init([&]{
|
||||
return compileContract(registrarCode, "GlobalRegistrar");
|
||||
});
|
||||
|
||||
sendMessage(*s_compiledRegistrar, true);
|
||||
sendMessage(compiled, true);
|
||||
BOOST_REQUIRE(m_transactionSuccessful);
|
||||
BOOST_REQUIRE(!m_output.empty());
|
||||
}
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
* Tests for a fixed fee registrar contract.
|
||||
*/
|
||||
|
||||
#include <libsolutil/LazyInit.h>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <optional>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
@@ -122,17 +125,18 @@ contract FixedFeeRegistrar is Registrar {
|
||||
}
|
||||
)DELIMITER";
|
||||
|
||||
static unique_ptr<bytes> s_compiledRegistrar;
|
||||
static LazyInit<bytes> s_compiledRegistrar;
|
||||
|
||||
class RegistrarTestFramework: public SolidityExecutionFramework
|
||||
{
|
||||
protected:
|
||||
void deployRegistrar()
|
||||
{
|
||||
if (!s_compiledRegistrar)
|
||||
s_compiledRegistrar = make_unique<bytes>(compileContract(registrarCode, "FixedFeeRegistrar"));
|
||||
bytes const& compiled = s_compiledRegistrar.init([&]{
|
||||
return compileContract(registrarCode, "FixedFeeRegistrar");
|
||||
});
|
||||
|
||||
sendMessage(*s_compiledRegistrar, true);
|
||||
sendMessage(compiled, true);
|
||||
BOOST_REQUIRE(m_transactionSuccessful);
|
||||
BOOST_REQUIRE(!m_output.empty());
|
||||
}
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
* Tests for a (comparatively) complex multisig wallet contract.
|
||||
*/
|
||||
|
||||
#include <libsolutil/LazyInit.h>
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <optional>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
@@ -434,7 +437,7 @@ contract Wallet is multisig, multiowned, daylimit {
|
||||
}
|
||||
)DELIMITER";
|
||||
|
||||
static unique_ptr<bytes> s_compiledWallet;
|
||||
static LazyInit<bytes> s_compiledWallet;
|
||||
|
||||
class WalletTestFramework: public SolidityExecutionFramework
|
||||
{
|
||||
@@ -446,11 +449,12 @@ protected:
|
||||
u256 _dailyLimit = 0
|
||||
)
|
||||
{
|
||||
if (!s_compiledWallet)
|
||||
s_compiledWallet = make_unique<bytes>(compileContract(walletCode, "Wallet"));
|
||||
bytes const& compiled = s_compiledWallet.init([&]{
|
||||
return compileContract(walletCode, "Wallet");
|
||||
});
|
||||
|
||||
bytes args = encodeArgs(u256(0x60), _required, _dailyLimit, u256(_owners.size()), _owners);
|
||||
sendMessage(*s_compiledWallet + args, true, _value);
|
||||
sendMessage(compiled + args, true, _value);
|
||||
BOOST_REQUIRE(m_transactionSuccessful);
|
||||
BOOST_REQUIRE(!m_output.empty());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
[
|
||||
{
|
||||
"absolutePath": "a",
|
||||
"exportedSymbols":
|
||||
@@ -218,3 +219,4 @@
|
||||
],
|
||||
"src": "0:160:3"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -140,6 +140,9 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
||||
return TestResult::FatalError;
|
||||
}
|
||||
|
||||
if (m_sources.size() > 1)
|
||||
m_result += "[\n";
|
||||
|
||||
for (size_t i = 0; i < m_sources.size(); i++)
|
||||
{
|
||||
ostringstream result;
|
||||
@@ -150,6 +153,9 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
|
||||
m_result += "\n";
|
||||
}
|
||||
|
||||
if (m_sources.size() > 1)
|
||||
m_result += "]\n";
|
||||
|
||||
bool resultsMatch = true;
|
||||
|
||||
replaceTagWithVersion(m_expectation);
|
||||
|
||||
@@ -12,6 +12,7 @@ contract c {
|
||||
l = data.length;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 2, 1, 1
|
||||
|
||||
@@ -9,5 +9,7 @@ contract c {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> FAILURE
|
||||
|
||||
@@ -13,6 +13,7 @@ contract c {
|
||||
if (l != 0x03) return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> false
|
||||
|
||||
@@ -13,6 +13,7 @@ contract c {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
contract c {
|
||||
bytes data;
|
||||
function test_short() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 15; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
|
||||
function test_long() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 33; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
|
||||
function test_pop() public returns (uint256 r) {
|
||||
assembly {
|
||||
sstore(data_slot, 0)
|
||||
}
|
||||
for (uint8 i = 0; i < 32; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
data.pop();
|
||||
assembly {
|
||||
r := sload(data_slot)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test_short() -> 1780731860627700044960722568376587075150542249149356309979516913770823710
|
||||
// test_long() -> 67
|
||||
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979440702
|
||||
@@ -0,0 +1,21 @@
|
||||
// Tests transition between short and long encoding both ways
|
||||
contract c {
|
||||
bytes data;
|
||||
|
||||
function test() public returns (uint256) {
|
||||
for (uint8 i = 0; i < 33; i++) {
|
||||
data.push(bytes1(i));
|
||||
}
|
||||
for (uint8 i = 0; i < data.length; i++)
|
||||
if (data[i] != bytes1(i)) return i;
|
||||
data.pop();
|
||||
data.pop();
|
||||
for (uint8 i = 0; i < data.length; i++)
|
||||
if (data[i] != bytes1(i)) return i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
||||
@@ -4,5 +4,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x9c1185a5c5e9fc54612808977ee8f548b2258d31000000000000000000000000
|
||||
|
||||
@@ -3,5 +3,7 @@ contract C {
|
||||
return sha256("");
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
|
||||
@@ -3,6 +3,8 @@ contract test {
|
||||
return ecrecover(h, v, r, s);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a(bytes32,uint8,bytes32,bytes32):
|
||||
// 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c,
|
||||
|
||||
@@ -4,6 +4,8 @@ contract test {
|
||||
return ecrecover(h, v, r, s);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// a(bytes32,uint8,bytes32,bytes32):
|
||||
// 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c,
|
||||
|
||||
@@ -6,5 +6,7 @@ contract C {
|
||||
return ecrecover(bytes32(uint(-1)), 1, bytes32(uint(2)), bytes32(uint(3)));
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0
|
||||
|
||||
@@ -11,5 +11,7 @@ contract C {
|
||||
);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0
|
||||
|
||||
@@ -16,5 +16,7 @@ contract C {
|
||||
return ecrecover(hash, v, r, s);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
function f(uint[][] memory arr) public pure {
|
||||
uint[][] memory arr2 = arr;
|
||||
assert(arr2[0].length == arr[0].length);
|
||||
assert(arr.length == arr2.length);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
uint[][] arr2;
|
||||
function f() public view {
|
||||
assert(arr2[0].length == arr[0].length);
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
function f(uint[][] memory arr2) public {
|
||||
arr = arr2;
|
||||
assert(arr2[0].length == arr[0].length);
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
function f() public view {
|
||||
uint[][] memory arr2 = arr;
|
||||
assert(arr2[0].length == arr[0].length);
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
mapping (uint => uint[]) map;
|
||||
function f() public view {
|
||||
assert(map[0].length == map[1].length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
mapping (uint => uint[]) map;
|
||||
function f(uint x, uint y) public view {
|
||||
require(x == y);
|
||||
assert(map[x].length == map[y].length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
mapping (uint => uint[][]) map;
|
||||
function f(uint x, uint y) public view {
|
||||
require(x == y);
|
||||
assert(map[x][0].length == map[y][0].length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint[] arr;
|
||||
}
|
||||
S s1;
|
||||
S s2;
|
||||
function f() public view {
|
||||
assert(s1.arr.length == s2.arr.length);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (76-80): Assertion checker does not yet support the type of this variable.
|
||||
// Warning: (83-87): Assertion checker does not yet support the type of this variable.
|
||||
// Warning: (126-132): Assertion checker does not yet support this expression.
|
||||
// Warning: (126-128): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning: (143-149): Assertion checker does not yet support this expression.
|
||||
// Warning: (143-145): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning: (119-157): Assertion violation happens here
|
||||
@@ -0,0 +1,22 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
struct S {
|
||||
uint[][] arr;
|
||||
}
|
||||
S s1;
|
||||
S s2;
|
||||
function f() public view {
|
||||
assert(s1.arr[0].length == s2.arr[0].length);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (78-82): Assertion checker does not yet support the type of this variable.
|
||||
// Warning: (85-89): Assertion checker does not yet support the type of this variable.
|
||||
// Warning: (128-134): Assertion checker does not yet support this expression.
|
||||
// Warning: (128-130): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning: (128-137): Assertion checker does not yet implement this expression.
|
||||
// Warning: (148-154): Assertion checker does not yet support this expression.
|
||||
// Warning: (148-150): Assertion checker does not yet implement type struct C.S storage ref
|
||||
// Warning: (148-157): Assertion checker does not yet implement this expression.
|
||||
// Warning: (121-165): Assertion violation happens here
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
function f(uint[][] memory arr) public pure {
|
||||
uint[][] memory arr2 = arr;
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(uint[] memory arr) public pure {
|
||||
uint[] memory arr2 = arr;
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
uint[] arr2;
|
||||
function f() public {
|
||||
arr2 = arr;
|
||||
assert(arr2.length == arr.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
function f() public view {
|
||||
uint x = arr.length;
|
||||
uint y = x;
|
||||
assert(arr.length == y);
|
||||
assert(arr.length != y);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (153-176): Assertion violation happens here
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
function f(uint[] memory marr) public {
|
||||
arr = marr;
|
||||
assert(marr.length == arr.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
function f() public view {
|
||||
uint[] memory marr = arr;
|
||||
assert(marr.length == arr.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
function f() public view {
|
||||
assert(arr.length == g().length);
|
||||
}
|
||||
function g() internal pure returns (uint[] memory) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] arr;
|
||||
function f() public view {
|
||||
uint[] memory arr2 = arr;
|
||||
arr2[2] = 3;
|
||||
assert(arr.length == arr2.length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
uint[][] arr2;
|
||||
function f() public {
|
||||
uint x = arr[2].length;
|
||||
uint y = arr[3].length;
|
||||
uint z = arr.length;
|
||||
arr[2][333] = 444;
|
||||
assert(arr[2].length == x);
|
||||
assert(arr[3].length == y);
|
||||
assert(arr.length == z);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
uint[][] arr2;
|
||||
function f() public {
|
||||
uint x = arr[2].length;
|
||||
uint y = arr[3].length;
|
||||
uint z = arr.length;
|
||||
arr[2][333] = 444;
|
||||
assert(arr[2].length != x);
|
||||
assert(arr[3].length != y);
|
||||
assert(arr.length != z);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (198-224): Assertion violation happens here
|
||||
// Warning: (228-254): Assertion violation happens here
|
||||
// Warning: (258-281): Assertion violation happens here
|
||||
@@ -0,0 +1,17 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
uint[][] arr2;
|
||||
function f() public {
|
||||
uint x = arr[2].length;
|
||||
uint y = arr[3].length;
|
||||
uint z = arr.length;
|
||||
uint t = arr[5].length;
|
||||
arr[5] = arr[8];
|
||||
assert(arr[2].length == x);
|
||||
assert(arr[3].length == y);
|
||||
assert(arr.length == z);
|
||||
assert(arr[5].length == t);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] arr;
|
||||
uint[][] arr2;
|
||||
function f() public {
|
||||
uint x = arr[2].length;
|
||||
uint y = arr[3].length;
|
||||
uint z = arr.length;
|
||||
uint t = arr[5].length;
|
||||
arr[5] = arr[8];
|
||||
assert(arr[2].length != x);
|
||||
assert(arr[3].length != y);
|
||||
assert(arr.length != z);
|
||||
assert(arr[5].length != t);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (222-248): Assertion violation happens here
|
||||
// Warning: (252-278): Assertion violation happens here
|
||||
// Warning: (282-305): Assertion violation happens here
|
||||
// Warning: (309-335): Assertion violation happens here
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f() public {
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (82-89): Empty array "pop" detected here.
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a[0].push();
|
||||
a[0].pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a[0].push();
|
||||
a[1].pop();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (111-121): Empty array "pop" detected here.
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
constructor() public {
|
||||
a.push();
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
constructor() public {
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (83-90): Empty array "pop" detected here.
|
||||
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f(uint l) public {
|
||||
for (uint i = 0; i < l; ++i) {
|
||||
a.push();
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f(uint l) public {
|
||||
for (uint i = 0; i < l; ++i) {
|
||||
a.push();
|
||||
a.pop();
|
||||
}
|
||||
a.pop();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (150-157): Empty array "pop" detected here.
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f(uint[] memory x, uint y) public {
|
||||
a.push(x);
|
||||
a[0].push(y);
|
||||
assert(a[0][a[0].length - 1] == y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f(uint[] memory x, uint y) public {
|
||||
a.push(x);
|
||||
a[0].push(y);
|
||||
a[0].pop();
|
||||
assert(a[0][a[0].length - 1] == y);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (162-177): Underflow (resulting value less than 0) happens here
|
||||
// Warning: (150-184): Assertion violation happens here
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f(uint x) public {
|
||||
a.push(x);
|
||||
assert(a[a.length - 1] == x);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint256[] x;
|
||||
constructor() public { x.push(42); }
|
||||
function f() public {
|
||||
x.push(23);
|
||||
assert(x[0] == 42 || x[0] == 23);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint256[] x;
|
||||
constructor() public { x.push(42); }
|
||||
function f() public {
|
||||
x.push(23);
|
||||
assert(x[0] == 42);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
contract C {
|
||||
uint256[] x;
|
||||
function f(uint256 l) public {
|
||||
require(x.length == 0);
|
||||
x.push(42);
|
||||
x.push(84);
|
||||
for(uint256 i = 0; i < l; ++i)
|
||||
x.push(23);
|
||||
assert(x[0] == 42 || x[0] == 23);
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint256[] x;
|
||||
function f(uint256 l) public {
|
||||
require(x.length == 0);
|
||||
x.push(42);
|
||||
x.push(84);
|
||||
for(uint256 i = 0; i < l; ++i)
|
||||
x.push(23);
|
||||
assert(x[0] == 42);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
uint[] storage b = a[0];
|
||||
b.push(8);
|
||||
assert(b[b.length - 1] == 8);
|
||||
// Safe but fails due to aliasing.
|
||||
assert(a[0][a[0].length - 1] == 8);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (217-232): Underflow (resulting value less than 0) happens here
|
||||
// Warning: (205-239): Assertion violation happens here
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a[0].push();
|
||||
a[0][0] = 16;
|
||||
uint[] storage b = a[0];
|
||||
b[0] = 32;
|
||||
assert(a[0][0] == 16);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (167-188): Assertion violation happens here
|
||||
@@ -0,0 +1,10 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a[0].push();
|
||||
assert(a[a.length - 1][0] == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[][] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
a[0].push();
|
||||
assert(a[a.length - 1][0] == 100);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (111-144): Assertion violation happens here
|
||||
@@ -0,0 +1,9 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
assert(a[a.length - 1] == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
uint[] a;
|
||||
function f() public {
|
||||
a.push();
|
||||
assert(a[a.length - 1] == 100);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (94-124): Assertion violation happens here
|
||||
@@ -34,9 +34,7 @@ library MerkleProof {
|
||||
}
|
||||
|
||||
// ----
|
||||
// Warning: (755-767): Assertion checker does not yet support this expression.
|
||||
// Warning: (988-991): Assertion checker does not yet implement type abi
|
||||
// Warning: (988-1032): Assertion checker does not yet implement this type of function call.
|
||||
// Warning: (1175-1178): Assertion checker does not yet implement type abi
|
||||
// Warning: (1175-1219): Assertion checker does not yet implement this type of function call.
|
||||
// Warning: (755-767): Assertion checker does not yet support this expression.
|
||||
|
||||
@@ -19,5 +19,7 @@ contract LoopFor2 {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (317-337): Error trying to invoke SMT solver.
|
||||
// Warning: (317-337): Assertion violation happens here
|
||||
// Warning: (341-360): Assertion violation happens here
|
||||
// Warning: (364-383): Assertion violation happens here
|
||||
|
||||
@@ -4,6 +4,7 @@ contract C
|
||||
{
|
||||
uint[][] a;
|
||||
function f(bool b) public {
|
||||
a[1][1] = 512;
|
||||
a[2][3] = 4;
|
||||
if (b)
|
||||
delete a;
|
||||
@@ -16,3 +17,4 @@ contract C
|
||||
// ====
|
||||
// SMTSolvers: z3
|
||||
// ----
|
||||
// Warning: (191-211): Assertion violation happens here
|
||||
|
||||
@@ -7,5 +7,4 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (86-101): Assertion checker does not yet support this expression.
|
||||
// Warning: (79-106): Assertion violation happens here
|
||||
|
||||
@@ -7,6 +7,4 @@ contract C
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (117-133): Assertion checker does not yet support this expression.
|
||||
// Warning: (137-153): Assertion checker does not yet support this expression.
|
||||
// Warning: (110-154): Assertion violation happens here
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
{
|
||||
"smtlib2responses":
|
||||
{
|
||||
"0x9c50514d749eabf3c13d97ad7d787e682dd99a114bad652b10a01b8c6ad6c1fb": "sat\n((|EVALEXPR_0| 1))\n",
|
||||
"0xb524e7c577188e2e36f0e67fead51269fa0f8b8fb41bff2d973dcf584d38cd1e": "sat\n((|EVALEXPR_0| 0))\n"
|
||||
"0x45598870c7c0bc4c4f61acad7e0dd9399fb28aa3df198379dd36a95d70814ef8": "sat\n((|EVALEXPR_0| 1))\n",
|
||||
"0xee335f8104fdb81b6e5fb418725923b81f7d78ffbd6bf95fb82e5593a1ac366a": "sat\n((|EVALEXPR_0| 0))\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"smtlib2responses":
|
||||
{
|
||||
"0x45c37a9829e623d7838d82b547d297cd446d6b5faff36c53a56862fcee50fb41": "sat\n((|EVALEXPR_0| 0))\n"
|
||||
"0x535c76d6b87d14bd4b4bf1014d14b8e91b648f073a68f9f267c4fe1df570bc14": "sat\n((|EVALEXPR_0| 0))\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b;
|
||||
function foo() public view {
|
||||
mapping (uint => uint) storage c = b;
|
||||
b = c;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (160-161): Mappings cannot be assigned to.
|
||||
@@ -0,0 +1,27 @@
|
||||
contract C {
|
||||
mapping (uint => address payable [ ]) public a = a ;
|
||||
}
|
||||
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b = a;
|
||||
}
|
||||
|
||||
contract F {
|
||||
mapping (uint => uint) a;
|
||||
mapping (uint => uint) b;
|
||||
|
||||
function foo() public {
|
||||
a = b;
|
||||
}
|
||||
}
|
||||
|
||||
contract G {
|
||||
uint x = 1;
|
||||
mapping (uint => uint) b = x;
|
||||
}
|
||||
// ----
|
||||
// TypeError: (17-67): Mappings cannot be assigned to.
|
||||
// TypeError: (120-148): Mappings cannot be assigned to.
|
||||
// TypeError: (263-264): Mappings cannot be assigned to.
|
||||
// TypeError: (312-340): Mappings cannot be assigned to.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract D {
|
||||
mapping (uint => uint) a;
|
||||
function foo() public view {
|
||||
mapping (uint => int) storage c = a;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (84-119): Type mapping(uint256 => uint256) is not implicitly convertible to expected type mapping(uint256 => int256).
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
This file is part of solidity.
|
||||
|
||||
solidity is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
solidity is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libsolutil/LazyInit.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace solidity::util::test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
void assertInitCalled(LazyInit<T> lazyInit, bool target)
|
||||
{
|
||||
bool initCalled = false;
|
||||
|
||||
lazyInit.init([&]{
|
||||
initCalled = true;
|
||||
return T();
|
||||
});
|
||||
|
||||
BOOST_REQUIRE_EQUAL(initCalled, target);
|
||||
}
|
||||
|
||||
// Take ownership to ensure that it doesn't "mutate"
|
||||
template<typename T>
|
||||
void assertNotEmpty(LazyInit<T> _lazyInit) { assertInitCalled(std::move(_lazyInit), false); }
|
||||
|
||||
// Take ownership to ensure that it doesn't "mutate"
|
||||
template<typename T>
|
||||
void assertEmpty(LazyInit<T> _lazyInit) { assertInitCalled(std::move(_lazyInit), true); }
|
||||
|
||||
template<typename T>
|
||||
T valueOf(LazyInit<T> _lazyInit)
|
||||
{
|
||||
return _lazyInit.init([&]{
|
||||
BOOST_REQUIRE(false); // this should never be called
|
||||
return T();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LazyInitTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(default_constructed_is_empty)
|
||||
{
|
||||
assertEmpty(LazyInit<int>());
|
||||
assertEmpty(LazyInit<int const>());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(initialized_is_not_empty)
|
||||
{
|
||||
LazyInit<int> lazyInit;
|
||||
lazyInit.init([]{ return 12; });
|
||||
|
||||
assertNotEmpty(std::move(lazyInit));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(init_returns_init_value)
|
||||
{
|
||||
LazyInit<int> lazyInit;
|
||||
|
||||
BOOST_CHECK_EQUAL(lazyInit.init([]{ return 12; }), 12);
|
||||
|
||||
// A second call to init should not change the value
|
||||
BOOST_CHECK_EQUAL(lazyInit.init([]{ return 42; }), 12);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(moved_from_is_empty)
|
||||
{
|
||||
{
|
||||
LazyInit<int> lazyInit;
|
||||
{ [[maybe_unused]] auto pilfered = std::move(lazyInit); }
|
||||
|
||||
assertEmpty(std::move(lazyInit));
|
||||
}
|
||||
|
||||
{
|
||||
LazyInit<int> lazyInit;
|
||||
lazyInit.init([]{ return 12; });
|
||||
|
||||
{ [[maybe_unused]] auto pilfered = std::move(lazyInit); }
|
||||
|
||||
assertEmpty(std::move(lazyInit));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(move_constructed_has_same_value_as_original)
|
||||
{
|
||||
LazyInit<int> original;
|
||||
original.init([]{ return 12; });
|
||||
|
||||
LazyInit<int> moveConstructed = std::move(original);
|
||||
BOOST_CHECK_EQUAL(valueOf(std::move(moveConstructed)), 12);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user