mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6494 from sifmelcara/fix-dead-code-eliminator
Fix variable decl scope issue in DeadCodeEliminator
This commit is contained in:
commit
7e0c6234ba
@ -38,6 +38,10 @@ namespace yul
|
||||
* Function definitions are retained as they might be called by earlier
|
||||
* code and thus are considered reachable.
|
||||
*
|
||||
* Because variables declared in a for loop's init block have their scope extended to the loop body,
|
||||
* we require ForLoopInitRewriter to run before this step.
|
||||
*
|
||||
* Prerequisite: ForLoopInitRewriter
|
||||
*/
|
||||
class DeadCodeEliminator: public ASTModifier
|
||||
{
|
||||
|
@ -71,11 +71,11 @@ void OptimiserSuite::run(
|
||||
VarDeclInitializer{}(ast);
|
||||
FunctionHoister{}(ast);
|
||||
BlockFlattener{}(ast);
|
||||
ForLoopInitRewriter{}(ast);
|
||||
DeadCodeEliminator{}(ast);
|
||||
FunctionGrouper{}(ast);
|
||||
EquivalentFunctionCombiner::run(ast);
|
||||
UnusedPruner::runUntilStabilised(*_dialect, ast, reservedIdentifiers);
|
||||
ForLoopInitRewriter{}(ast);
|
||||
BlockFlattener{}(ast);
|
||||
StructuralSimplifier{*_dialect}(ast);
|
||||
BlockFlattener{}(ast);
|
||||
|
@ -207,6 +207,7 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
||||
else if (m_optimizerStep == "deadCodeEliminator")
|
||||
{
|
||||
disambiguate();
|
||||
ForLoopInitRewriter{}(*m_ast);
|
||||
DeadCodeEliminator{}(*m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "ssaTransform")
|
||||
|
@ -17,8 +17,8 @@
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
@ -18,8 +18,8 @@
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
@ -18,8 +18,8 @@
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
for { stop() let i_0 := 0 } lt(i_0,2) { i_0 := add(i_0,1) }
|
||||
{
|
||||
let i_1 := i_0
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// stop()
|
||||
// }
|
@ -16,8 +16,8 @@
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
@ -16,8 +16,8 @@
|
||||
// step: deadCodeEliminator
|
||||
// ----
|
||||
// {
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
@ -20,8 +20,8 @@
|
||||
// ----
|
||||
// {
|
||||
// let b := 20
|
||||
// let a := 20
|
||||
// for {
|
||||
// let a := 20
|
||||
// }
|
||||
// lt(a, 40)
|
||||
// {
|
||||
|
Loading…
Reference in New Issue
Block a user