diff options
19 files changed, 156 insertions, 46 deletions
diff --git a/Changelog.md b/Changelog.md index 0fbce7c5..ef0a03c2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,11 +1,12 @@ ### 0.4.24 (unreleased) Features: + * Build System: Update internal dependency of jsoncpp to 1.8.4, which introduces more strictness and reduces memory usage. * Optimizer: Remove unnecessary masking of the result of known short instructions (``ADDRESS``, ``CALLER``, ``ORIGIN`` and ``COINBASE``). * Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature. Bugfixes: - + * Type Checker: Warn about empty tuple components (this will turn into an error with version 0.5.0). ### 0.4.23 (2018-04-19) diff --git a/cmake/jsoncpp.cmake b/cmake/jsoncpp.cmake index 6ddf4c74..3d6b37ed 100644 --- a/cmake/jsoncpp.cmake +++ b/cmake/jsoncpp.cmake @@ -6,17 +6,15 @@ else() set(JSONCPP_CMAKE_COMMAND ${CMAKE_COMMAND}) endif() -# Disable implicit fallthrough warning in jsoncpp for gcc >= 7 until the upstream handles it properly -if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) - set(JSONCCP_EXTRA_FLAGS -Wno-implicit-fallthrough) -else() - set(JSONCCP_EXTRA_FLAGS "") -endif() - +include(GNUInstallDirs) set(prefix "${CMAKE_BINARY_DIR}/deps") -set(JSONCPP_LIBRARY "${prefix}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}") +set(JSONCPP_LIBRARY "${prefix}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}jsoncpp${CMAKE_STATIC_LIBRARY_SUFFIX}") set(JSONCPP_INCLUDE_DIR "${prefix}/include") +if(NOT MSVC) + set(JSONCPP_EXTRA_FLAGS "-std=c++11") +endif() + set(byproducts "") if(CMAKE_VERSION VERSION_GREATER 3.1) set(byproducts BUILD_BYPRODUCTS "${JSONCPP_LIBRARY}") @@ -25,9 +23,9 @@ endif() ExternalProject_Add(jsoncpp-project PREFIX "${prefix}" DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/deps/downloads" - DOWNLOAD_NAME jsoncpp-1.7.7.tar.gz - URL https://github.com/open-source-parsers/jsoncpp/archive/1.7.7.tar.gz - URL_HASH SHA256=087640ebcf7fbcfe8e2717a0b9528fff89c52fcf69fa2a18cc2b538008098f97 + DOWNLOAD_NAME jsoncpp-1.8.4.tar.gz + URL https://github.com/open-source-parsers/jsoncpp/archive/1.8.4.tar.gz + URL_HASH SHA256=c49deac9e0933bcb7044f08516861a2d560988540b23de2ac1ad443b219afdb6 CMAKE_COMMAND ${JSONCPP_CMAKE_COMMAND} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} @@ -36,7 +34,7 @@ ExternalProject_Add(jsoncpp-project -DCMAKE_POSITION_INDEPENDENT_CODE=${BUILD_SHARED_LIBS} -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF - -DCMAKE_CXX_FLAGS=${JSONCCP_EXTRA_FLAGS} + -DCMAKE_CXX_FLAGS=${JSONCPP_EXTRA_FLAGS} # Overwrite build and install commands to force Release build on MSVC. BUILD_COMMAND cmake --build <BINARY_DIR> --config Release INSTALL_COMMAND cmake --build <BINARY_DIR> --config Release --target install diff --git a/libdevcore/JSON.cpp b/libdevcore/JSON.cpp index d99b3bc6..6317cc89 100644 --- a/libdevcore/JSON.cpp +++ b/libdevcore/JSON.cpp @@ -28,8 +28,8 @@ using namespace std; static_assert( - (JSONCPP_VERSION_MAJOR == 1) && (JSONCPP_VERSION_MINOR == 7) && (JSONCPP_VERSION_PATCH == 7), - "Unexpected jsoncpp version: " JSONCPP_VERSION_STRING ". Expecting 1.7.7." + (JSONCPP_VERSION_MAJOR == 1) && (JSONCPP_VERSION_MINOR == 8) && (JSONCPP_VERSION_PATCH == 4), + "Unexpected jsoncpp version: " JSONCPP_VERSION_STRING ". Expecting 1.8.4." ); namespace dev diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 66b0af58..ce98eb24 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1406,8 +1406,10 @@ bool TypeChecker::visit(TupleExpression const& _tuple) } else { + bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); bool isPure = true; TypePointer inlineArrayType; + for (size_t i = 0; i < components.size(); ++i) { // Outside of an lvalue-context, the only situation where a component can be empty is (x,). @@ -1418,6 +1420,17 @@ bool TypeChecker::visit(TupleExpression const& _tuple) components[i]->accept(*this); types.push_back(type(*components[i])); + if (types[i]->category() == Type::Category::Tuple) + if (dynamic_cast<TupleType const&>(*types[i]).components().empty()) + { + if (_tuple.isInlineArray()) + m_errorReporter.fatalTypeError(components[i]->location(), "Array component cannot be empty."); + if (v050) + m_errorReporter.fatalTypeError(components[i]->location(), "Tuple component cannot be empty."); + else + m_errorReporter.warning(components[i]->location(), "Tuple component cannot be empty."); + } + // Note: code generation will visit each of the expression even if they are not assigned from. if (types[i]->category() == Type::Category::RationalNumber && components.size() > 1) if (!dynamic_cast<RationalNumberType const&>(*types[i]).mobileType()) @@ -1652,10 +1665,18 @@ bool TypeChecker::visit(FunctionCall const& _functionCall) if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression())) { + string msg; if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3) - m_errorReporter.warning(_functionCall.location(), "\"sha3\" has been deprecated in favour of \"keccak256\""); + msg = "\"sha3\" has been deprecated in favour of \"keccak256\""; else if (functionName->name() == "suicide" && functionType->kind() == FunctionType::Kind::Selfdestruct) - m_errorReporter.warning(_functionCall.location(), "\"suicide\" has been deprecated in favour of \"selfdestruct\""); + msg = "\"suicide\" has been deprecated in favour of \"selfdestruct\""; + if (!msg.empty()) + { + if (v050) + m_errorReporter.typeError(_functionCall.location(), msg); + else + m_errorReporter.warning(_functionCall.location(), msg); + } } if (!m_insideEmitStatement && functionType->kind() == FunctionType::Kind::Event) { diff --git a/scripts/create_source_tarball.sh b/scripts/create_source_tarball.sh index 9e66799a..4e930707 100755 --- a/scripts/create_source_tarball.sh +++ b/scripts/create_source_tarball.sh @@ -32,7 +32,7 @@ REPO_ROOT="$(dirname "$0")"/.. fi # Add dependencies mkdir -p "$SOLDIR/deps/downloads/" 2>/dev/null || true - wget -O "$SOLDIR/deps/downloads/jsoncpp-1.7.7.tar.gz" https://github.com/open-source-parsers/jsoncpp/archive/1.7.7.tar.gz + wget -O "$SOLDIR/deps/downloads/jsoncpp-1.8.4.tar.gz" https://github.com/open-source-parsers/jsoncpp/archive/1.8.4.tar.gz mkdir -p "$REPO_ROOT/upload" tar czf "$REPO_ROOT/upload/solidity_$versionstring.tar.gz" -C "$TEMPDIR" "solidity_$versionstring" rm -r "$TEMPDIR" diff --git a/scripts/install_cmake.sh b/scripts/install_cmake.sh index 00d013b9..e334b2c9 100755 --- a/scripts/install_cmake.sh +++ b/scripts/install_cmake.sh @@ -18,6 +18,8 @@ esac BIN=$PREFIX/bin +PATH=$PREFIX/bin:$PATH + if test -f $BIN/cmake && ($BIN/cmake --version | grep -q "$VERSION"); then echo "CMake $VERSION already installed in $BIN" else diff --git a/scripts/release_ppa.sh b/scripts/release_ppa.sh index 375b4d1b..b1601336 100755 --- a/scripts/release_ppa.sh +++ b/scripts/release_ppa.sh @@ -76,7 +76,7 @@ mv solidity solc # Fetch jsoncpp dependency mkdir -p ./solc/deps/downloads/ 2>/dev/null || true -wget -O ./solc/deps/downloads/jsoncpp-1.7.7.tar.gz https://github.com/open-source-parsers/jsoncpp/archive/1.7.7.tar.gz +wget -O ./solc/deps/downloads/jsoncpp-1.8.4.tar.gz https://github.com/open-source-parsers/jsoncpp/archive/1.8.4.tar.gz # Determine version cd solc diff --git a/scripts/travis-emscripten/build_emscripten.sh b/scripts/travis-emscripten/build_emscripten.sh index fd643429..f49ff5b2 100755 --- a/scripts/travis-emscripten/build_emscripten.sh +++ b/scripts/travis-emscripten/build_emscripten.sh @@ -40,6 +40,12 @@ if ! type git &>/dev/null; then apt-get -y install git-core fi +if ! type wget &>/dev/null; then + # We need wget to install cmake + apt-get update + apt-get -y install wget +fi + WORKSPACE=/root/project # Increase nodejs stack size @@ -67,6 +73,10 @@ rm -rf b2 libs doc tools more bin.v2 status ) echo -en 'travis_fold:end:compiling_boost\\r' +echo -en 'travis_fold:start:install_cmake.sh\\r' +source $WORKSPACE/scripts/install_cmake.sh +echo -en 'travis_fold:end:install_cmake.sh\\r' + # Build dependent components and solidity itself echo -en 'travis_fold:start:compiling_solidity\\r' cd $WORKSPACE diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 97cf0410..3081b8f2 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5823,7 +5823,7 @@ BOOST_AUTO_TEST_CASE(bare_others) CHECK_WARNING("contract C { function f() pure public { assert; } }", "Statement has no effect."); // This is different because it does have overloads. CHECK_ERROR("contract C { function f() pure public { require; } }", TypeError, "No matching declaration found after variable lookup."); - CHECK_WARNING("contract C { function f() pure public { suicide; } }", "Statement has no effect."); + CHECK_WARNING("contract C { function f() pure public { selfdestruct; } }", "Statement has no effect."); } BOOST_AUTO_TEST_CASE(pure_statement_in_for_loop) @@ -6958,31 +6958,6 @@ BOOST_AUTO_TEST_CASE(invalid_literal_in_tuple) CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(warn_about_sha3) -{ - char const* text = R"( - contract test { - function f() pure public { - bytes32 x = sha3(uint8(1)); - x; - } - } - )"; - CHECK_WARNING(text, "\"sha3\" has been deprecated in favour of \"keccak256\""); -} - -BOOST_AUTO_TEST_CASE(warn_about_suicide) -{ - char const* text = R"( - contract test { - function f() public { - suicide(1); - } - } - )"; - CHECK_WARNING(text, "\"suicide\" has been deprecated in favour of \"selfdestruct\""); -} - BOOST_AUTO_TEST_CASE(address_overload_resolution) { char const* text = R"( diff --git a/test/libsolidity/syntaxTests/deprecated_functions.sol b/test/libsolidity/syntaxTests/deprecated_functions.sol new file mode 100644 index 00000000..57ee484a --- /dev/null +++ b/test/libsolidity/syntaxTests/deprecated_functions.sol @@ -0,0 +1,12 @@ +contract test { + function f() pure public { + bytes32 x = sha3(uint8(1)); + x; + } + function g() public { + suicide(1); + } +} +// ---- +// Warning: (58-72): "sha3" has been deprecated in favour of "keccak256" +// Warning: (107-117): "suicide" has been deprecated in favour of "selfdestruct" diff --git a/test/libsolidity/syntaxTests/deprecated_functions_050.sol b/test/libsolidity/syntaxTests/deprecated_functions_050.sol new file mode 100644 index 00000000..7e36543b --- /dev/null +++ b/test/libsolidity/syntaxTests/deprecated_functions_050.sol @@ -0,0 +1,13 @@ +pragma experimental "v0.5.0"; +contract test { + function f() pure public { + bytes32 x = sha3(uint8(1)); + x; + } + function g() public { + suicide(1); + } +} +// ---- +// TypeError: (88-102): "sha3" has been deprecated in favour of "keccak256" +// TypeError: (137-147): "suicide" has been deprecated in favour of "selfdestruct" diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol index 617af543..ef6da75d 100644 --- a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol +++ b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol @@ -19,7 +19,7 @@ contract C { // ---- // TypeError: (117-118): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. -// Warning: (191-198): "sha3" has been deprecated in favour of "keccak256" +// TypeError: (191-198): "sha3" has been deprecated in favour of "keccak256" // TypeError: (196-197): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. // TypeError: (277-278): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. // TypeError: (361-362): Cannot perform packed encoding for a literal. Please convert it to an explicit type first. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol new file mode 100644 index 00000000..3e40b155 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_event.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.4.3; +contract C { + event SomeEvent(); + function a() public { + (SomeEvent(), 7); + } +} +// ---- +// Warning: (95-106): Invoking events without "emit" prefix is deprecated. +// Warning: (95-106): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol new file mode 100644 index 00000000..aec5ff2a --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_event_050.sol @@ -0,0 +1,10 @@ +pragma experimental "v0.5.0"; +contract C { + event SomeEvent(); + function a() public { + (SomeEvent(), 7); + } +} +// ---- +// TypeError: (101-112): Event invocations have to be prefixed by "emit". +// TypeError: (101-112): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol new file mode 100644 index 00000000..05b54442 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_function.sol @@ -0,0 +1,12 @@ +pragma solidity ^0.4.3; +contract C { + function f() private pure {} + function a() public pure { + bool x = true; + bool y = true; + (x) ? (f(), y = false) : (f(), y = false); + } +} +// ---- +// Warning: (162-165): Tuple component cannot be empty. +// Warning: (181-184): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol new file mode 100644 index 00000000..c4b9e03f --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_function_050.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract C { + function f() private pure {} + function a() public pure { + bool x = true; + bool y = true; + (x) ? (f(), y = false) : (f(), y = false); + } +} +// ---- +// TypeError: (168-171): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol new file mode 100644 index 00000000..cba30c1b --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue.sol @@ -0,0 +1,13 @@ +pragma solidity ^0.4.3; +contract C { + function f() private pure {} + function a() public { + uint x; + uint y; + (x, y) = (f(), f()); + } +} +// ---- +// Warning: (146-149): Tuple component cannot be empty. +// Warning: (151-154): Tuple component cannot be empty. +// TypeError: (145-155): Type tuple(tuple(),tuple()) is not implicitly convertible to expected type tuple(uint256,uint256). diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol new file mode 100644 index 00000000..b0691778 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_050.sol @@ -0,0 +1,11 @@ +pragma experimental "v0.5.0"; +contract C { + function f() private pure {} + function a() public { + uint x; + uint y; + (x, y) = (f(), f()); + } +} +// ---- +// TypeError: (152-155): Tuple component cannot be empty. diff --git a/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol new file mode 100644 index 00000000..f8b2ae7e --- /dev/null +++ b/test/libsolidity/syntaxTests/types/empty_tuple_lvalue_array.sol @@ -0,0 +1,11 @@ +pragma solidity ^0.4.3; +contract C { + function f() private pure {} + function a() public { + uint x; + uint y; + (x, y) = [f(), f()]; + } +} +// ---- +// TypeError: (146-149): Array component cannot be empty. |