From fb06451f45c6e1dc0ffe304c2074ead6ba03f1ec Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 15 Apr 2019 15:15:48 +0200 Subject: [PATCH] Add assertion that DeadCodeEliminator needs ForLoopInitRewriter. --- libyul/optimiser/DeadCodeEliminator.cpp | 6 ++++++ libyul/optimiser/DeadCodeEliminator.h | 1 + test/libyul/YulOptimizerTest.cpp | 1 + test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libyul/optimiser/DeadCodeEliminator.cpp b/libyul/optimiser/DeadCodeEliminator.cpp index 47f302d4f..c405f2d76 100644 --- a/libyul/optimiser/DeadCodeEliminator.cpp +++ b/libyul/optimiser/DeadCodeEliminator.cpp @@ -67,6 +67,12 @@ auto findFirstTerminatingStatement(Block& _block) } } +void DeadCodeEliminator::operator()(ForLoop& _for) +{ + yulAssert(_for.pre.statements.empty(), "DeadCodeEliminator needs ForLoopInitRewriter as a prerequisite."); + ASTModifier::operator()(_for); +} + void DeadCodeEliminator::operator()(Block& _block) { auto& statements = _block.statements; diff --git a/libyul/optimiser/DeadCodeEliminator.h b/libyul/optimiser/DeadCodeEliminator.h index 1d464badd..c4d60cf4c 100644 --- a/libyul/optimiser/DeadCodeEliminator.h +++ b/libyul/optimiser/DeadCodeEliminator.h @@ -47,6 +47,7 @@ class DeadCodeEliminator: public ASTModifier { public: using ASTModifier::operator(); + void operator()(ForLoop& _for) override; void operator()(Block& _block) override; }; diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index e5fe097f7..3eec1233f 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -192,6 +192,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con disambiguate(); NameDispenser nameDispenser{*m_dialect, *m_ast}; ExpressionSplitter{*m_dialect, nameDispenser}(*m_ast); + ForLoopInitRewriter{}(*m_ast); CommonSubexpressionEliminator{*m_dialect}(*m_ast); ExpressionSimplifier::run(*m_dialect, *m_ast); UnusedPruner::runUntilStabilised(*m_dialect, *m_ast); diff --git a/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul b/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul index f18d73f26..a2365cf0d 100644 --- a/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul +++ b/test/libyul/yulOptimizerTests/fullSimplify/inside_for.yul @@ -6,8 +6,8 @@ // step: fullSimplify // ---- // { +// let a := 10 // for { -// let a := 10 // } // iszero(iszero(a)) // {