Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth
2020-06-15 17:11:41 +02:00
132 changed files with 1083 additions and 417 deletions
+2 -2
View File
@@ -606,7 +606,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays)
BOTH_ENCODERS(
for (size_t size = 1; size < 15; size++)
{
for (size_t width: {1, 2, 4, 5, 7, 15, 16, 17, 31, 32})
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
{
string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size));
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8));
@@ -651,7 +651,7 @@ BOOST_AUTO_TEST_CASE(bytesNN_arrays_dyn)
BOTH_ENCODERS(
for (size_t size = 0; size < 15; size++)
{
for (size_t width: {1, 2, 4, 5, 7, 15, 16, 17, 31, 32})
for (size_t width: {1u, 2u, 4u, 5u, 7u, 15u, 16u, 17u, 31u, 32u})
{
string source = boost::algorithm::replace_all_copy(sourceCode, "SIZE", to_string(size));
source = boost::algorithm::replace_all_copy(source, "UINTWIDTH", to_string(width * 8));
+1 -1
View File
@@ -134,7 +134,7 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
c.analyze();
else
{
SourceReferenceFormatterHuman formatter(_stream, _formatted);
SourceReferenceFormatterHuman formatter(_stream, _formatted, false);
for (auto const& error: c.errors())
formatter.printErrorInformation(*error);
return TestResult::FatalError;
+1 -1
View File
@@ -118,7 +118,7 @@ TestCase::TestResult GasTest::run(ostream& _stream, string const& _linePrefix, b
if (!compiler().parseAndAnalyze() || !compiler().compile())
{
SourceReferenceFormatterHuman formatter(_stream, _formatted);
SourceReferenceFormatterHuman formatter(_stream, _formatted, false);
for (auto const& error: compiler().errors())
formatter.printErrorInformation(*error);
return TestResult::FatalError;
+6 -6
View File
@@ -116,21 +116,21 @@ TestCase::TestResult SMTCheckerJSONTest::run(ostream& _stream, string const& _li
!location["end"].isInt()
)
BOOST_THROW_EXCEPTION(runtime_error("Error must have a SourceLocation with start and end."));
int start = location["start"].asInt();
int end = location["end"].asInt();
size_t start = location["start"].asUInt();
size_t end = location["end"].asUInt();
std::string sourceName;
if (location.isMember("source") && location["source"].isString())
sourceName = location["source"].asString();
if (start >= static_cast<int>(preamble.size()))
if (start >= preamble.size())
start -= preamble.size();
if (end >= static_cast<int>(preamble.size()))
if (end >= preamble.size())
end -= preamble.size();
m_errorList.emplace_back(SyntaxTestError{
error["type"].asString(),
error["message"].asString(),
sourceName,
start,
end
static_cast<int>(start),
static_cast<int>(end)
});
}
}
@@ -143,8 +143,8 @@ bytes compileFirstExpression(
);
context.resetVisitedNodes(contract);
context.setMostDerivedContract(*contract);
unsigned parametersSize = _localVariables.size(); // assume they are all one slot on the stack
context.adjustStackOffset(parametersSize);
size_t parametersSize = _localVariables.size(); // assume they are all one slot on the stack
context.adjustStackOffset(static_cast<int>(parametersSize));
for (vector<string> const& variable: _localVariables)
context.addVariable(
dynamic_cast<VariableDeclaration const&>(resolveDeclaration(*sourceUnit, variable, resolver)),
+5
View File
@@ -26,6 +26,7 @@
#include <libsolidity/interface/CompilerStack.h>
#include <liblangutil/Exceptions.h>
#include <libsolutil/Exceptions.h>
#include <libsolidity/interface/Natspec.h>
#include <boost/test/unit_test.hpp>
@@ -56,6 +57,10 @@ public:
generatedDocumentation = m_compilerStack.natspecDev(_contractName);
Json::Value expectedDocumentation;
util::jsonParseStrict(_expectedDocumentationString, expectedDocumentation);
expectedDocumentation["version"] = Json::Value(Natspec::c_natspecVersion);
expectedDocumentation["kind"] = Json::Value(_userDocumentation ? "user" : "dev");
BOOST_CHECK_MESSAGE(
expectedDocumentation == generatedDocumentation,
"Expected:\n" << expectedDocumentation.toStyledString() <<
+1 -1
View File
@@ -491,7 +491,7 @@ BOOST_AUTO_TEST_CASE(constant_optimization_early_exit)
#endif
#endif
#if __SANITIZE_ADDRESS__
maxDuration = size_t(-1);
maxDuration = numeric_limits<size_t>::max();
BOOST_TEST_MESSAGE("Disabled constant optimizer run time check for address sanitizer build.");
#endif
BOOST_CHECK_MESSAGE(duration <= maxDuration, "Compilation of constants took longer than 20 seconds.");
+1 -1
View File
@@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(inline_asm_end_location)
bool visit(InlineAssembly const& _inlineAsm) override
{
auto loc = _inlineAsm.location();
auto asmStr = loc.source->source().substr(loc.start, loc.end - loc.start);
auto asmStr = loc.source->source().substr(static_cast<size_t>(loc.start), static_cast<size_t>(loc.end - loc.start));
BOOST_CHECK_EQUAL(asmStr, "assembly { a := 0x12345678 }");
visited = true;
+3 -3
View File
@@ -354,9 +354,9 @@ BOOST_AUTO_TEST_CASE(basic_compilation)
BOOST_CHECK(contract["abi"].isArray());
BOOST_CHECK_EQUAL(util::jsonCompactPrint(contract["abi"]), "[]");
BOOST_CHECK(contract["devdoc"].isObject());
BOOST_CHECK_EQUAL(util::jsonCompactPrint(contract["devdoc"]), "{\"methods\":{}}");
BOOST_CHECK_EQUAL(util::jsonCompactPrint(contract["devdoc"]), R"({"kind":"dev","methods":{},"version":1})");
BOOST_CHECK(contract["userdoc"].isObject());
BOOST_CHECK_EQUAL(util::jsonCompactPrint(contract["userdoc"]), "{\"methods\":{}}");
BOOST_CHECK_EQUAL(util::jsonCompactPrint(contract["userdoc"]), R"({"kind":"user","methods":{},"version":1})");
BOOST_CHECK(contract["evm"].isObject());
/// @TODO check evm.methodIdentifiers, legacyAssembly, bytecode, deployedBytecode
BOOST_CHECK(contract["evm"]["bytecode"].isObject());
@@ -466,7 +466,7 @@ BOOST_AUTO_TEST_CASE(compilation_error)
{
BOOST_CHECK_EQUAL(
util::jsonCompactPrint(error),
"{\"component\":\"general\",\"formattedMessage\":\"fileA:1:23: ParserError: Expected identifier but got '}'\\n"
"{\"component\":\"general\",\"errorCode\":\"2314\",\"formattedMessage\":\"fileA:1:23: ParserError: Expected identifier but got '}'\\n"
"contract A { function }\\n ^\\n\",\"message\":\"Expected identifier but got '}'\","
"\"severity\":\"error\",\"sourceLocation\":{\"end\":23,\"file\":\"fileA\",\"start\":22},\"type\":\"ParserError\"}"
);
+2 -2
View File
@@ -98,9 +98,9 @@ void SyntaxTest::filterObtainedErrors()
{
// ignore the version & license pragma inserted by the testing tool when calculating locations.
if (location->start >= static_cast<int>(preamble.size()))
locationStart = location->start - (preamble.size());
locationStart = location->start - static_cast<int>(preamble.size());
if (location->end >= static_cast<int>(preamble.size()))
locationEnd = location->end - (preamble.size());
locationEnd = location->end - static_cast<int>(preamble.size());
if (location->source)
sourceName = location->source->name();
}
@@ -0,0 +1,12 @@
contract CalldataTest {
function test(bytes calldata x) public returns (bytes calldata) {
return x;
}
function tester(bytes calldata x) public returns (byte) {
return this.test(x)[2];
}
}
// ====
// EVMVersion: >=byzantium
// ----
// tester(bytes): 0x20, 0x08, "abcdefgh" -> "c"
@@ -0,0 +1,17 @@
contract C {
struct S {
uint a;
bytes b;
mapping(uint => uint) c;
uint[] d;
}
uint shifter;
S public s;
constructor() public {
s.a = 7;
s.b = "abc";
s.c[0] = 9;
}
}
// ----
// s() -> 0x07, 0x40, 0x03, 0x6162630000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,17 @@
library D {
function f(bytes calldata _x) internal pure returns (bytes calldata) {
return _x;
}
function g(bytes calldata _x) internal pure returns (bytes memory) {
return _x;
}
}
contract C {
using D for bytes;
function f(bytes calldata _x) public pure returns (byte, byte) {
return (_x.f()[0], _x.g()[0]);
}
}
// ----
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,20 @@
library D {
function f(bytes calldata _x) public pure returns (bytes calldata) {
return _x;
}
function g(bytes calldata _x) public pure returns (bytes memory) {
return _x;
}
}
contract C {
using D for bytes;
function f(bytes calldata _x) public pure returns (byte, byte) {
return (_x.f()[0], _x.g()[0]);
}
}
// ====
// EVMVersion: >homestead
// ----
// library: D
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,17 @@
library D {
function f(bytes calldata _x) internal pure returns (byte) {
return _x[0];
}
function g(bytes memory _x) internal pure returns (byte) {
return _x[0];
}
}
contract C {
using D for bytes;
function f(bytes calldata _x) public pure returns (byte, byte) {
return (_x.f(), _x.g());
}
}
// ----
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,20 @@
library D {
function f(bytes calldata _x) public pure returns (byte) {
return _x[0];
}
function g(bytes memory _x) public pure returns (byte) {
return _x[0];
}
}
contract C {
using D for bytes;
function f(bytes calldata _x) public pure returns (byte, byte) {
return (_x.f(), _x.g());
}
}
// ====
// EVMVersion: >homestead
// ----
// library: D
// f(bytes): 0x20, 4, "abcd" -> 0x6100000000000000000000000000000000000000000000000000000000000000, 0x6100000000000000000000000000000000000000000000000000000000000000
@@ -0,0 +1,25 @@
struct Struct { uint x; }
library L {
function f(Struct storage _x) internal view returns (uint256) {
return _x.x;
}
}
contract C {
using L for Struct;
Struct s;
function h(Struct storage _s) internal view returns (uint) {
// _s is pointer
return _s.f();
}
function g() public returns (uint, uint) {
s.x = 7;
// s is reference
return (s.f(), h(s));
}
}
// ----
// g() -> 7, 7
@@ -0,0 +1,21 @@
contract C {
struct S {
uint256 a;
uint256 b;
}
function f() public pure returns (uint256 a, uint256 b){
assembly {
// Make free memory dirty to check that the struct allocation cleans it up again.
let freeMem := mload(0x40)
mstore(freeMem, 42)
mstore(add(freeMem, 32), 42)
}
S memory s;
return (s.a, s.b);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0, 0
@@ -0,0 +1,39 @@
pragma experimental ABIEncoderV2;
contract C {
struct S {
uint a;
uint[] b;
uint c;
}
S s;
constructor() public {
s.a = 42;
s.b.push(1);
s.b.push(2);
s.b.push(3);
s.c = 21;
}
function f(S memory m) public pure returns (uint, uint[] memory, uint) {
return (m.a, m.b, m.c);
}
function g(S calldata c) external pure returns (uint, uint, uint, uint, uint, uint) {
return (c.a, c.b.length, c.c, c.b[0], c.b[1], c.b[2]);
}
function g2(S calldata c1, S calldata c2) external pure returns (uint, uint, uint, uint, uint, uint) {
return (c1.a, c1.c, c2.a, c2.b.length, c2.c, c2.b[0]);
}
function h() external view returns (uint, uint, uint, uint, uint, uint) {
return (s.a, s.b.length, s.c, s.b[0], s.b[1], s.b[2]);
}
}
// ====
// EVMVersion: >homestead
// compileViaYul: also
// ----
// f((uint256,uint256[],uint256)): 0x20, 42, 0x60, 21, 3, 1, 2, 3 -> 42, 0x60, 21, 3, 1, 2, 3
// g((uint256,uint256[],uint256)): 0x20, 42, 0x60, 21, 3, 1, 2, 3 -> 42, 3, 21, 1, 2, 3
// g2((uint256,uint256[],uint256),(uint256,uint256[],uint256)): 0x40, 0x0120, 42, 0x60, 21, 2, 1, 2, 3, 7, 0x80, 9, 0, 1, 17 -> 42, 21, 7, 1, 9, 17
// h() -> 42, 3, 21, 1, 2, 3
@@ -22,4 +22,3 @@ contract C
}
}
// ----
// Warning: (130-144): Error trying to invoke SMT solver.
@@ -14,6 +14,4 @@ contract C
}
}
// ----
// Warning: (296-309): Error trying to invoke SMT solver.
// Warning: (176-181): Overflow (resulting value larger than 2**256 - 1) happens here
// Warning: (296-309): Assertion violation happens here
@@ -19,7 +19,5 @@ 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
@@ -0,0 +1,9 @@
library D { function f(bytes calldata) internal pure {} }
contract C {
using D for bytes;
function f(bytes memory _x) public pure {
_x.f();
}
}
// ----
// TypeError: (136-140): Member "f" not found or not visible after argument-dependent lookup in bytes memory.
+2 -2
View File
@@ -348,10 +348,10 @@ string BytesUtils::formatBytesRange(
size_t BytesUtils::countRightPaddedZeros(bytes const& _bytes)
{
return find_if(
return static_cast<size_t>(find_if(
_bytes.rbegin(),
_bytes.rend(),
[](uint8_t b) { return b != '\0'; }
) - _bytes.rbegin();
) - _bytes.rbegin());
}
@@ -66,7 +66,7 @@ void testFunctionCall(
ABI_CHECK(_call.expectations.rawBytes(), _expectations);
BOOST_REQUIRE_EQUAL(_call.displayMode, _mode);
BOOST_REQUIRE_EQUAL(_call.value.value, _value.value);
BOOST_REQUIRE_EQUAL(size_t(_call.value.unit), size_t(_value.unit));
BOOST_REQUIRE_EQUAL(static_cast<size_t>(_call.value.unit), static_cast<size_t>(_value.unit));
BOOST_REQUIRE_EQUAL(_call.arguments.comment, _argumentComment);
BOOST_REQUIRE_EQUAL(_call.expectations.comment, _expectationComment);