aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md1
-rw-r--r--docs/miscellaneous.rst6
-rw-r--r--docs/using-the-compiler.rst24
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp2
-rw-r--r--test/boostTest.cpp1
-rw-r--r--test/cmdlineTests/data_storage.sol15
-rw-r--r--test/cmdlineTests/data_storage.sol.args1
-rw-r--r--test/cmdlineTests/data_storage.sol.stdout7
-rw-r--r--test/libsolidity/GasCosts.cpp89
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp2
10 files changed, 137 insertions, 11 deletions
diff --git a/Changelog.md b/Changelog.md
index 65477695..b5d98484 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -5,6 +5,7 @@ Language Features:
Compiler Features:
* Inline Assembly: Improve error messages around invalid function argument count.
+ * Code Generator: Use codecopy for string constants more aggressively.
* Code Generator: Use binary search for dispatch function if more efficient. The size/speed tradeoff can be tuned using ``--optimize-runs``.
* SMTChecker: Support mathematical and cryptographic functions in an uninterpreted way.
* Type Checker: Add an additional reason to be displayed when type conversion fails.
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst
index 017d5b81..5a6f3875 100644
--- a/docs/miscellaneous.rst
+++ b/docs/miscellaneous.rst
@@ -224,9 +224,9 @@ for displaying the current position in the source code inside a debugger
or for breakpoint handling.
Both kinds of source mappings use integer identifiers to refer to source files.
-These are regular array indices into a list of source files usually called
-``"sourceList"``, which is part of the combined-json and the output of
-the json / npm compiler.
+The identifier of a source file is stored in
+``output['sources'][sourceName]['id']`` where ``output`` is the output of the
+standard-json compiler interface parsed as JSON.
.. note ::
In the case of instructions that are not associated with any particular source file,
diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst
index 9ba6caa5..4749ef1f 100644
--- a/docs/using-the-compiler.rst
+++ b/docs/using-the-compiler.rst
@@ -200,15 +200,27 @@ Input Description
"MyLib": "0x123123..."
}
}
- // The following can be used to select desired outputs.
- // If this field is omitted, then the compiler loads and does type checking, but will not generate any outputs apart from errors.
- // The first level key is the file name and the second is the contract name, where empty contract name refers to the file itself,
- // while the star refers to all of the contracts.
+ // The following can be used to select desired outputs based
+ // on file and contract names.
+ // If this field is omitted, then the compiler loads and does type checking,
+ // but will not generate any outputs apart from errors.
+ // The first level key is the file name and the second level key is the contract name.
+ // An empty contract name is used for outputs that are not tied to a contract
+ // but to the whole source file like the AST.
+ // A star as contract name refers to all contracts in the file.
+ // Similarly, a star as a file name matches all files.
+ // To select all outputs the compiler can possibly generate, use
+ // "outputSelection: { "*": { "*": [ "*" ], "": [ "*" ] } }"
+ // but note that this might slow down the compilation process needlessly.
//
// The available output types are as follows:
- // abi - ABI
+ //
+ // File level (needs empty string as contract name):
// ast - AST of all source files
// legacyAST - legacy AST of all source files
+ //
+ // Contract level (needs the contract name or "*"):
+ // abi - ABI
// devdoc - Developer documentation (natspec)
// userdoc - User documentation (natspec)
// metadata - Metadata
@@ -281,7 +293,7 @@ Output Description
// This contains the file-level outputs. In can be limited/filtered by the outputSelection settings.
sources: {
"sourceFile.sol": {
- // Identifier (used in source maps)
+ // Identifier of the source (used in source maps)
id: 1,
// The AST object
ast: {},
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index 7d2ad9d2..259f1620 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -1205,7 +1205,7 @@ void CompilerUtils::storeStringData(bytesConstRef _data)
{
//@todo provide both alternatives to the optimiser
// stack: mempos
- if (_data.size() <= 128)
+ if (_data.size() <= 32)
{
for (unsigned i = 0; i < _data.size(); i += 32)
{
diff --git a/test/boostTest.cpp b/test/boostTest.cpp
index 034aaef3..d6e75cb9 100644
--- a/test/boostTest.cpp
+++ b/test/boostTest.cpp
@@ -160,6 +160,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
"LLLEndToEndTest",
#endif
"GasMeterTests",
+ "GasCostTests",
"SolidityEndToEndTest",
"SolidityOptimizer"
})
diff --git a/test/cmdlineTests/data_storage.sol b/test/cmdlineTests/data_storage.sol
new file mode 100644
index 00000000..cc602cc9
--- /dev/null
+++ b/test/cmdlineTests/data_storage.sol
@@ -0,0 +1,15 @@
+pragma solidity >=0.0;
+
+contract C {
+ function f() pure public {
+ require(false, "1234567890123456789012345678901");
+ require(false, "12345678901234567890123456789012");
+ require(false, "123456789012345678901234567890123");
+ require(false, "1234567890123456789012345678901234");
+ require(false, "12345678901234567890123456789012345");
+ require(false, "123456789012345678901234567890123456");
+ require(false, "123456789012345678901234567890121234567890123456789012345678901");
+ require(false, "1234567890123456789012345678901212345678901234567890123456789012");
+ require(false, "12345678901234567890123456789012123456789012345678901234567890123");
+ }
+}
diff --git a/test/cmdlineTests/data_storage.sol.args b/test/cmdlineTests/data_storage.sol.args
new file mode 100644
index 00000000..3684987e
--- /dev/null
+++ b/test/cmdlineTests/data_storage.sol.args
@@ -0,0 +1 @@
+--gas
diff --git a/test/cmdlineTests/data_storage.sol.stdout b/test/cmdlineTests/data_storage.sol.stdout
new file mode 100644
index 00000000..4a5250f7
--- /dev/null
+++ b/test/cmdlineTests/data_storage.sol.stdout
@@ -0,0 +1,7 @@
+
+======= data_storage.sol:C =======
+Gas estimation:
+construction:
+ 306 + 264400 = 264706
+external:
+ f(): 263
diff --git a/test/libsolidity/GasCosts.cpp b/test/libsolidity/GasCosts.cpp
new file mode 100644
index 00000000..15658a91
--- /dev/null
+++ b/test/libsolidity/GasCosts.cpp
@@ -0,0 +1,89 @@
+/*
+ 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/>.
+*/
+/**
+ * Tests that check that the cost of certain operations stay within range.
+ */
+
+#include <test/libsolidity/SolidityExecutionFramework.h>
+
+#include <cmath>
+
+using namespace std;
+using namespace langutil;
+using namespace dev::eth;
+using namespace dev::solidity;
+using namespace dev::test;
+
+namespace dev
+{
+namespace solidity
+{
+namespace test
+{
+
+#define CHECK_GAS(_gasNoOpt, _gasOpt, _tolerance) \
+ do \
+ { \
+ u256 gasOpt{_gasOpt}; \
+ u256 gasNoOpt{_gasNoOpt}; \
+ u256 tolerance{_tolerance}; \
+ u256 gas = m_optimize ? gasOpt : gasNoOpt; \
+ u256 diff = gas < m_gasUsed ? m_gasUsed - gas : gas - m_gasUsed; \
+ BOOST_CHECK_MESSAGE( \
+ diff <= tolerance, \
+ "Gas used: " + \
+ m_gasUsed.str() + \
+ " - expected: " + \
+ gas.str() + \
+ " (tolerance: " + \
+ tolerance.str() + \
+ ")" \
+ ); \
+ } while(0)
+
+BOOST_FIXTURE_TEST_SUITE(GasCostTests, SolidityExecutionFramework)
+
+BOOST_AUTO_TEST_CASE(string_storage)
+{
+ char const* sourceCode = R"(
+ contract C {
+ function f() pure public {
+ require(false, "Not Authorized. This function can only be called by the custodian or owner of this contract");
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ if (Options::get().evmVersion() <= EVMVersion::byzantium())
+ CHECK_GAS(134435, 130591, 100);
+ else
+ CHECK_GAS(127225, 124873, 100);
+ if (Options::get().evmVersion() >= EVMVersion::byzantium())
+ {
+ callContractFunction("f()");
+ if (Options::get().evmVersion() == EVMVersion::byzantium())
+ CHECK_GAS(21551, 21526, 20);
+ else
+ CHECK_GAS(21546, 21526, 20);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+}
+}
+}
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index c6135a72..dfa60fc5 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -12245,7 +12245,7 @@ BOOST_AUTO_TEST_CASE(include_creation_bytecode_only_once)
compileAndRun(sourceCode);
BOOST_CHECK_LE(
double(m_compiler.object("Double").bytecode.size()),
- 1.1 * double(m_compiler.object("Single").bytecode.size())
+ 1.2 * double(m_compiler.object("Single").bytecode.size())
);
}