aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorCJentzsch <jentzsch.software@gmail.com>2015-05-13 16:35:51 +0800
committerCJentzsch <jentzsch.software@gmail.com>2015-05-13 16:35:51 +0800
commit1230062ff09c5d209a2c581b6cfcda664b576e12 (patch)
tree667b90fcd523848af62620d505e020313057dd9e /libsolidity
parent1532574367d20f050cddad4b68c3c7f9645e44b4 (diff)
parente3aca3dca9e1e0b940d74295d2e8ac0556b362b6 (diff)
downloaddexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar.gz
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar.bz2
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar.lz
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar.xz
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.tar.zst
dexon-solidity-1230062ff09c5d209a2c581b6cfcda664b576e12.zip
Merge remote-tracking branch 'upstream/develop' into addTests
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/SolidityABIJSON.cpp43
-rw-r--r--libsolidity/SolidityCompiler.cpp59
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp22
-rw-r--r--libsolidity/SolidityOptimizer.cpp95
4 files changed, 188 insertions, 31 deletions
diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp
index 26d0110b..f9bf78d0 100644
--- a/libsolidity/SolidityABIJSON.cpp
+++ b/libsolidity/SolidityABIJSON.cpp
@@ -525,6 +525,49 @@ BOOST_AUTO_TEST_CASE(constructor_abi)
checkInterface(sourceCode, interface);
}
+
+BOOST_AUTO_TEST_CASE(return_param_in_abi)
+{
+ // bug #1801
+ char const* sourceCode = R"(
+ contract test {
+ enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
+ function test(ActionChoices param) {}
+ function ret() returns(ActionChoices){
+ ActionChoices action = ActionChoices.GoLeft;
+ return action;
+ }
+ }
+ )";
+
+ char const* interface = R"(
+ [
+ {
+ "constant" : false,
+ "inputs" : [],
+ "name" : "ret",
+ "outputs" : [
+ {
+ "name" : "",
+ "type" : "uint8"
+ }
+ ],
+ "type" : "function"
+ },
+ {
+ "inputs": [
+ {
+ "name": "param",
+ "type": "uint8"
+ }
+ ],
+ "type": "constructor"
+ }
+ ]
+ )";
+ checkInterface(sourceCode, interface);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/libsolidity/SolidityCompiler.cpp b/libsolidity/SolidityCompiler.cpp
index aa83c465..dda7847e 100644
--- a/libsolidity/SolidityCompiler.cpp
+++ b/libsolidity/SolidityCompiler.cpp
@@ -116,36 +116,35 @@ BOOST_AUTO_TEST_CASE(ifStatement)
bytes code = compileContract(sourceCode);
unsigned shift = 60;
unsigned boilerplateSize = 73;
- bytes expectation({byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x0,
- byte(Instruction::DUP1),
- byte(Instruction::PUSH1), byte(0x1b + shift), // "true" target
- byte(Instruction::JUMPI),
- // new check "else if" condition
- byte(Instruction::DUP1),
- byte(Instruction::ISZERO),
- byte(Instruction::PUSH1), byte(0x13 + shift),
- byte(Instruction::JUMPI),
- // "else" body
- byte(Instruction::PUSH1), 0x4f,
- byte(Instruction::POP),
- byte(Instruction::PUSH1), byte(0x17 + shift), // exit path of second part
- byte(Instruction::JUMP),
- // "else if" body
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x4e,
- byte(Instruction::POP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), byte(0x1f + shift),
- byte(Instruction::JUMP),
- // "if" body
- byte(Instruction::JUMPDEST),
- byte(Instruction::PUSH1), 0x4d,
- byte(Instruction::POP),
- byte(Instruction::JUMPDEST),
- byte(Instruction::JUMPDEST),
- byte(Instruction::POP),
- byte(Instruction::JUMP)});
+ bytes expectation({
+ byte(Instruction::JUMPDEST),
+ byte(Instruction::PUSH1), 0x0,
+ byte(Instruction::DUP1),
+ byte(Instruction::ISZERO),
+ byte(Instruction::PUSH1), byte(0x0f + shift), // "false" target
+ byte(Instruction::JUMPI),
+ // "if" body
+ byte(Instruction::PUSH1), 0x4d,
+ byte(Instruction::POP),
+ byte(Instruction::PUSH1), byte(0x21 + shift),
+ byte(Instruction::JUMP),
+ // new check "else if" condition
+ byte(Instruction::JUMPDEST),
+ byte(Instruction::DUP1),
+ byte(Instruction::ISZERO),
+ byte(Instruction::ISZERO),
+ byte(Instruction::PUSH1), byte(0x1c + shift),
+ byte(Instruction::JUMPI),
+ // "else if" body
+ byte(Instruction::PUSH1), 0x4e,
+ byte(Instruction::POP),
+ byte(Instruction::PUSH1), byte(0x20 + shift),
+ byte(Instruction::JUMP),
+ // "else" body
+ byte(Instruction::JUMPDEST),
+ byte(Instruction::PUSH1), 0x4f,
+ byte(Instruction::POP),
+ });
checkCodePresentAt(code, expectation, boilerplateSize);
}
diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp
index c317dad9..4ec7b8bd 100644
--- a/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -508,6 +508,28 @@ BOOST_AUTO_TEST_CASE(function_external_types)
}
}
+BOOST_AUTO_TEST_CASE(enum_external_type)
+{
+ // bug #1801
+ ASTPointer<SourceUnit> sourceUnit;
+ char const* text = R"(
+ contract Test {
+ enum ActionChoices { GoLeft, GoRight, GoStraight, Sit }
+ function boo(ActionChoices enumArg) external returns (uint ret) {
+ ret = 5;
+ }
+ })";
+ ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed");
+ for (ASTPointer<ASTNode> const& node: sourceUnit->getNodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ {
+ auto functions = contract->getDefinedFunctions();
+ if (functions.empty())
+ continue;
+ BOOST_CHECK_EQUAL("boo(uint8)", functions[0]->externalSignature());
+ }
+}
+
BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion)
{
char const* text = R"(
diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp
index 3cb6a536..efc9316b 100644
--- a/libsolidity/SolidityOptimizer.cpp
+++ b/libsolidity/SolidityOptimizer.cpp
@@ -29,6 +29,7 @@
#include <libevmasm/CommonSubexpressionEliminator.h>
#include <libevmasm/ControlFlowGraph.h>
#include <libevmasm/Assembly.h>
+#include <libevmasm/BlockDeduplicator.h>
using namespace std;
using namespace dev::eth;
@@ -125,7 +126,7 @@ public:
BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end());
}
- void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation)
+ AssemblyItems getCFG(AssemblyItems const& _input)
{
AssemblyItems output = _input;
// Running it four times should be enough for these tests.
@@ -138,6 +139,12 @@ public:
back_inserter(optItems));
output = move(optItems);
}
+ return output;
+ }
+
+ void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation)
+ {
+ AssemblyItems output = getCFG(_input);
BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end());
}
@@ -251,6 +258,63 @@ BOOST_AUTO_TEST_CASE(function_calls)
compareVersions("f(uint256)", 36);
}
+BOOST_AUTO_TEST_CASE(storage_write_in_loops)
+{
+ char const* sourceCode = R"(
+ contract test {
+ uint d;
+ function f(uint a) returns (uint r) {
+ var x = d;
+ for (uint i = 1; i < a * a; i++) {
+ r = d;
+ d = i;
+ }
+
+ }
+ }
+ )";
+ compileBothVersions(sourceCode);
+ compareVersions("f(uint256)", 0);
+ compareVersions("f(uint256)", 10);
+ compareVersions("f(uint256)", 36);
+}
+
+BOOST_AUTO_TEST_CASE(retain_information_in_branches)
+{
+ // This tests that the optimizer knows that we already have "z == sha3(y)" inside both branches.
+ char const* sourceCode = R"(
+ contract c {
+ bytes32 d;
+ uint a;
+ function f(uint x, bytes32 y) returns (uint r_a, bytes32 r_d) {
+ bytes32 z = sha3(y);
+ if (x > 8) {
+ z = sha3(y);
+ a = x;
+ } else {
+ z = sha3(y);
+ a = x;
+ }
+ r_a = a;
+ r_d = d;
+ }
+ }
+ )";
+ compileBothVersions(sourceCode);
+ compareVersions("f(uint256,bytes32)", 0, "abc");
+ compareVersions("f(uint256,bytes32)", 8, "def");
+ compareVersions("f(uint256,bytes32)", 10, "ghi");
+
+ m_optimize = true;
+ bytes optimizedBytecode = compileAndRun(sourceCode, 0, "c");
+ size_t numSHA3s = 0;
+ eth::eachInstruction(optimizedBytecode, [&](Instruction _instr, u256 const&) {
+ if (_instr == eth::Instruction::SHA3)
+ numSHA3s++;
+ });
+ BOOST_CHECK_EQUAL(1, numSHA3s);
+}
+
BOOST_AUTO_TEST_CASE(cse_intermediate_swap)
{
eth::KnownState state;
@@ -868,6 +932,35 @@ BOOST_AUTO_TEST_CASE(control_flow_graph_do_not_remove_returned_to)
checkCFG(input, {u256(2)});
}
+BOOST_AUTO_TEST_CASE(block_deduplicator)
+{
+ AssemblyItems input{
+ AssemblyItem(PushTag, 2),
+ AssemblyItem(PushTag, 1),
+ AssemblyItem(PushTag, 3),
+ u256(6),
+ eth::Instruction::SWAP3,
+ eth::Instruction::JUMP,
+ AssemblyItem(Tag, 1),
+ u256(6),
+ eth::Instruction::SWAP3,
+ eth::Instruction::JUMP,
+ AssemblyItem(Tag, 2),
+ u256(6),
+ eth::Instruction::SWAP3,
+ eth::Instruction::JUMP,
+ AssemblyItem(Tag, 3)
+ };
+ BlockDeduplicator dedup(input);
+ dedup.deduplicate();
+
+ set<u256> pushTags;
+ for (AssemblyItem const& item: input)
+ if (item.type() == PushTag)
+ pushTags.insert(item.data());
+ BOOST_CHECK_EQUAL(pushTags.size(), 2);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}