From cfe24c3c2a60d59c0075e82fed044232baec4974 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 24 Apr 2015 11:42:30 +0200 Subject: Try to keep source location during optimization. --- libsolidity/SolidityOptimizer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/SolidityOptimizer.cpp b/libsolidity/SolidityOptimizer.cpp index af9b5146..ceb9c68d 100644 --- a/libsolidity/SolidityOptimizer.cpp +++ b/libsolidity/SolidityOptimizer.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -84,9 +85,20 @@ public: AssemblyItems getCSE(AssemblyItems const& _input) { + // add dummy locations to each item so that we can check that they are not deleted + AssemblyItems input = _input; + for (AssemblyItem& item: input) + item.setLocation(SourceLocation(1, 3, make_shared(""))); + eth::CommonSubexpressionEliminator cse; - BOOST_REQUIRE(cse.feedItems(_input.begin(), _input.end()) == _input.end()); - return cse.getOptimizedItems(); + BOOST_REQUIRE(cse.feedItems(input.begin(), input.end()) == input.end()); + AssemblyItems output = cse.getOptimizedItems(); + + for (AssemblyItem const& item: output) + { + BOOST_CHECK(item == Instruction::POP || !item.getLocation().isEmpty()); + } + return output; } void checkCSE(AssemblyItems const& _input, AssemblyItems const& _expectation) -- cgit