From 4035f82881d757efa3323f60c4fc7eebf1956cb1 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Wed, 6 Jan 2021 13:50:21 +0100 Subject: [PATCH] Tests for memoryloadresolver --- test/libyul/YulOptimizerTest.cpp | 15 ++++++++++ .../memoryLoadResolver/calldataload.yul | 29 +++++++++++++++++++ .../memoryLoadResolver/simple.yul | 17 +++++++++++ .../memoryLoadResolver/smoke.yul | 5 ++++ 4 files changed, 66 insertions(+) create mode 100644 test/libyul/yulOptimizerTests/memoryLoadResolver/calldataload.yul create mode 100644 test/libyul/yulOptimizerTests/memoryLoadResolver/simple.yul create mode 100644 test/libyul/yulOptimizerTests/memoryLoadResolver/smoke.yul diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 9a8a32836..9fb08bbc0 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -433,6 +434,20 @@ TestCase::TestResult YulOptimizerTest::run(ostream& _stream, string const& _line fakeUnreachableGenerator(*obj.code); StackLimitEvader::run(*m_context, obj, fakeUnreachableGenerator.fakeUnreachables); } + else if (m_optimizerStep == "memoryLoadResolver") + { + disambiguate(); + ForLoopInitRewriter::run(*m_context, *m_object->code); + ExpressionSplitter::run(*m_context, *m_object->code); + SSATransform::run(*m_context, *m_object->code); + + MemoryLoadResolver::run(*m_context, *m_object->code); + + // Cleanup + UnusedPruner::run(*m_context, *m_object->code); + ExpressionJoiner::run(*m_context, *m_object->code); + ExpressionJoiner::run(*m_context, *m_object->code); + } else { AnsiColorized(_stream, _formatted, {formatting::BOLD, formatting::RED}) << _linePrefix << "Invalid optimizer step: " << m_optimizerStep << endl; diff --git a/test/libyul/yulOptimizerTests/memoryLoadResolver/calldataload.yul b/test/libyul/yulOptimizerTests/memoryLoadResolver/calldataload.yul new file mode 100644 index 000000000..bb401965a --- /dev/null +++ b/test/libyul/yulOptimizerTests/memoryLoadResolver/calldataload.yul @@ -0,0 +1,29 @@ +{ + let key := 64 + let value := 128 + mstore(key, value) + + if callvalue() { revert(0, 0) } + + let _1 := 0 + let c := calldatasize() + + // Does not invalidate location 64 + calldatacopy(value, _1, c) + + // Should be replaced by out := value + let out := mload(key) + sstore(0, out) +} +// ---- +// step: memoryLoadResolver +// +// { +// let key := 64 +// let value := 128 +// mstore(key, value) +// if callvalue() { revert(0, 0) } +// let _1 := 0 +// calldatacopy(value, _1, calldatasize()) +// sstore(0, value) +// } diff --git a/test/libyul/yulOptimizerTests/memoryLoadResolver/simple.yul b/test/libyul/yulOptimizerTests/memoryLoadResolver/simple.yul new file mode 100644 index 000000000..18faa82ff --- /dev/null +++ b/test/libyul/yulOptimizerTests/memoryLoadResolver/simple.yul @@ -0,0 +1,17 @@ +{ + let key := 64 + let value := 128 + mstore(key, value) + + // should be replaced by sstore(0, value) + sstore(0, mload(key)) +} +// ---- +// step: memoryLoadResolver +// +// { +// let key := 64 +// let value := 128 +// mstore(key, value) +// sstore(0, value) +// } diff --git a/test/libyul/yulOptimizerTests/memoryLoadResolver/smoke.yul b/test/libyul/yulOptimizerTests/memoryLoadResolver/smoke.yul new file mode 100644 index 000000000..b47ea9a33 --- /dev/null +++ b/test/libyul/yulOptimizerTests/memoryLoadResolver/smoke.yul @@ -0,0 +1,5 @@ +{ } +// ---- +// step: memoryLoadResolver +// +// { }