Merge pull request #7418 from ethereum/ssaReverseFix

Fix SSA reverser for declaration + self-assignment
This commit is contained in:
chriseth 2019-09-12 20:02:18 +02:00 committed by GitHub
commit 63a8cda1d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 12 deletions

View File

@ -56,18 +56,24 @@ void SSAReverser::operator()(Block& _block)
identifier && identifier &&
identifier->name == varDecl->variables.front().name identifier->name == varDecl->variables.front().name
) )
return make_vector<Statement>( {
Assignment{ // in the special case a == a_1, just remove the assignment
std::move(assignment->location), if (assignment->variableNames.front().name == identifier->name)
assignment->variableNames, return make_vector<Statement>(std::move(_stmt1));
std::move(varDecl->value) else
}, return make_vector<Statement>(
VariableDeclaration{ Assignment{
std::move(varDecl->location), std::move(assignment->location),
std::move(varDecl->variables), assignment->variableNames,
std::make_unique<Expression>(std::move(assignment->variableNames.front())) std::move(varDecl->value)
} },
); VariableDeclaration{
std::move(varDecl->location),
std::move(varDecl->variables),
std::make_unique<Expression>(std::move(assignment->variableNames.front()))
}
);
}
} }
// Replaces // Replaces
// let a_1 := E // let a_1 := E

View File

@ -40,6 +40,13 @@ class AssignmentCounter;
* a := E * a := E
* let a_1 := a * let a_1 := a
* *
* In the special case
* let a := E
* a := a
*
* the redundant assignment "a := a" is removed.
*
*
* Secondly, the SSA transform will rewrite * Secondly, the SSA transform will rewrite
* *
* let a := E * let a := E

View File

@ -0,0 +1,8 @@
{
let a := calldataload(0)
a := a
}
// ====
// step: ssaReverser
// ----
// { let a := calldataload(0) }