diff options
author | chriseth <chris@ethereum.org> | 2019-01-08 07:07:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-08 07:07:42 +0800 |
commit | 6414d63906d1a768d4f8829eca49d6020630a261 (patch) | |
tree | 196cc1b8fbe18f8a4fb96146cc6c85654313d676 /test | |
parent | 8da3aa14ded6fdbeb14822c3fd1524bd597d50df (diff) | |
parent | 937fc8538eed632ee114f48d5cecd1c63dd05f87 (diff) | |
download | dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar.gz dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar.bz2 dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar.lz dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar.xz dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.tar.zst dexon-solidity-6414d63906d1a768d4f8829eca49d6020630a261.zip |
Merge pull request #5716 from ethereum/fixDataSizeOffset
Fix data size offset and properly provide builtins.
Diffstat (limited to 'test')
-rw-r--r-- | test/libyul/ObjectParser.cpp | 30 | ||||
-rw-r--r-- | test/libyul/Parser.cpp | 2 | ||||
-rw-r--r-- | test/libyul/YulOptimizerTest.cpp | 10 | ||||
-rw-r--r-- | test/libyul/yulOptimizerTests/commonSubexpressionEliminator/object_access.yul | 23 | ||||
-rw-r--r-- | test/libyul/yulOptimizerTests/expressionSplitter/object_access.yul | 21 | ||||
-rw-r--r-- | test/tools/yulopti.cpp | 2 |
6 files changed, 81 insertions, 7 deletions
diff --git a/test/libyul/ObjectParser.cpp b/test/libyul/ObjectParser.cpp index bb88e4da..13a95788 100644 --- a/test/libyul/ObjectParser.cpp +++ b/test/libyul/ObjectParser.cpp @@ -250,6 +250,36 @@ BOOST_AUTO_TEST_CASE(to_string) BOOST_CHECK_EQUAL(asmStack.print(), expectation); } +BOOST_AUTO_TEST_CASE(arg_to_dataoffset_must_be_literal) +{ + string code = R"( + object "outer" { + code { let x := "outer" let y := dataoffset(x) } + } + )"; + CHECK_ERROR(code, TypeError, "Function expects direct literals as arguments."); +} + +BOOST_AUTO_TEST_CASE(arg_to_datasize_must_be_literal) +{ + string code = R"( + object "outer" { + code { let x := "outer" let y := datasize(x) } + } + )"; + CHECK_ERROR(code, TypeError, "Function expects direct literals as arguments."); +} + +BOOST_AUTO_TEST_CASE(args_to_datacopy_are_arbitrary) +{ + string code = R"( + object "outer" { + code { let x := 0 let y := 2 let s := 3 datacopy(x, y, s) } + } + )"; + BOOST_CHECK(successParse(code)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index df7e32a1..897f18ae 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -331,7 +331,7 @@ BOOST_AUTO_TEST_CASE(builtins_analysis) { return _name == "builtin"_yulstring ? &f : nullptr; } - BuiltinFunction f{"builtin"_yulstring, vector<Type>(2), vector<Type>(3), false}; + BuiltinFunction f{"builtin"_yulstring, vector<Type>(2), vector<Type>(3), false, false}; }; shared_ptr<Dialect> dialect = make_shared<SimpleDialect>(); diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 1b392e0f..0e3203cb 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -122,7 +122,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con else if (m_optimizerStep == "expressionSplitter") { NameDispenser nameDispenser{*m_dialect, *m_ast}; - ExpressionSplitter{nameDispenser}(*m_ast); + ExpressionSplitter{*m_dialect, nameDispenser}(*m_ast); } else if (m_optimizerStep == "expressionJoiner") { @@ -133,7 +133,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con { disambiguate(); NameDispenser nameDispenser{*m_dialect, *m_ast}; - ExpressionSplitter{nameDispenser}(*m_ast); + ExpressionSplitter{*m_dialect, nameDispenser}(*m_ast); ExpressionJoiner::run(*m_ast); ExpressionJoiner::run(*m_ast); } @@ -158,7 +158,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con (FunctionHoister{})(*m_ast); (FunctionGrouper{})(*m_ast); NameDispenser nameDispenser{*m_dialect, *m_ast}; - ExpressionSplitter{nameDispenser}(*m_ast); + ExpressionSplitter{*m_dialect, nameDispenser}(*m_ast); FullInliner(*m_ast, nameDispenser).run(); ExpressionJoiner::run(*m_ast); } @@ -182,7 +182,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con { disambiguate(); NameDispenser nameDispenser{*m_dialect, *m_ast}; - ExpressionSplitter{nameDispenser}(*m_ast); + ExpressionSplitter{*m_dialect, nameDispenser}(*m_ast); CommonSubexpressionEliminator{*m_dialect}(*m_ast); ExpressionSimplifier::run(*m_dialect, *m_ast); UnusedPruner::runUntilStabilised(*m_dialect, *m_ast); @@ -260,7 +260,7 @@ void YulOptimizerTest::printIndented(ostream& _stream, string const& _output, st bool YulOptimizerTest::parse(ostream& _stream, string const& _linePrefix, bool const _formatted) { - m_dialect = m_yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVM(); + m_dialect = m_yul ? yul::Dialect::yul() : yul::EVMDialect::strictAssemblyForEVMObjects(); ErrorList errors; ErrorReporter errorReporter(errors); shared_ptr<Scanner> scanner = make_shared<Scanner>(CharStream(m_source, "")); diff --git a/test/libyul/yulOptimizerTests/commonSubexpressionEliminator/object_access.yul b/test/libyul/yulOptimizerTests/commonSubexpressionEliminator/object_access.yul new file mode 100644 index 00000000..5cfa3e6e --- /dev/null +++ b/test/libyul/yulOptimizerTests/commonSubexpressionEliminator/object_access.yul @@ -0,0 +1,23 @@ +{ + // Arguments to ``datasize`` and ``dataoffset`` need to be + // literals. We cannot simplify their arguments, but we can + // simplify them as a full expression. + // ``datacopy`` does not have this restriction. + let r := "abc" + let a := datasize("abc") + let x := dataoffset("abc") + // should be replaced by a + let y := datasize("abc") + datacopy("abc", x, y) + mstore(a, x) +} +// ---- +// commonSubexpressionEliminator +// { +// let r := "abc" +// let a := datasize("abc") +// let x := dataoffset("abc") +// let y := a +// datacopy(r, x, a) +// mstore(a, x) +// } diff --git a/test/libyul/yulOptimizerTests/expressionSplitter/object_access.yul b/test/libyul/yulOptimizerTests/expressionSplitter/object_access.yul new file mode 100644 index 00000000..2689ab6f --- /dev/null +++ b/test/libyul/yulOptimizerTests/expressionSplitter/object_access.yul @@ -0,0 +1,21 @@ +{ + // We should never split arguments to ``dataoffset`` + // or ``datasize`` because they need to be literals + let x := dataoffset("abc") + let y := datasize("abc") + // datacopy is fine, though + datacopy(mload(0), mload(1), mload(2)) +} +// ---- +// expressionSplitter +// { +// let x := dataoffset("abc") +// let y := datasize("abc") +// let _1 := 2 +// let _2 := mload(_1) +// let _3 := 1 +// let _4 := mload(_3) +// let _5 := 0 +// let _6 := mload(_5) +// datacopy(_6, _4, _2) +// } diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index 8ef56ffe..ac21fd91 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -149,7 +149,7 @@ public: (VarDeclInitializer{})(*m_ast); break; case 'x': - ExpressionSplitter{*m_nameDispenser}(*m_ast); + ExpressionSplitter{*m_dialect, *m_nameDispenser}(*m_ast); break; case 'j': ExpressionJoiner::run(*m_ast); |