Merge pull request #5641 from ethereum/supportUnassigned

[Yul] Support unassigned variables in the SSA value tracker and the data flow analyzer.
This commit is contained in:
chriseth
2018-12-13 11:33:45 +01:00
committed by GitHub
10 changed files with 65 additions and 13 deletions
+7 -2
View File
@@ -136,17 +136,22 @@ void DataFlowAnalyzer::operator()(Block& _block)
void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expression* _value)
{
static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}};
clearValues(_variables);
MovableChecker movableChecker;
if (_value)
movableChecker.visit(*_value);
if (_variables.size() == 1)
else
for (auto const& var: _variables)
m_value[var] = &zero;
if (_value && _variables.size() == 1)
{
YulString name = *_variables.begin();
// Expression has to be movable and cannot contain a reference
// to the variable that will be assigned to.
if (_value && movableChecker.movable() && !movableChecker.referencedVariables().count(name))
if (movableChecker.movable() && !movableChecker.referencedVariables().count(name))
m_value[name] = _value;
}
+2
View File
@@ -36,6 +36,8 @@ namespace yul
* Tracks assignments and is used as base class for both Rematerialiser and
* Common Subexpression Eliminator.
*
* A special zero constant expression is used for the default value of variables.
*
* Prerequisite: Disambiguator
*/
class DataFlowAnalyzer: public ASTModifier
+5 -4
View File
@@ -35,11 +35,12 @@ void SSAValueTracker::operator()(Assignment const& _assignment)
void SSAValueTracker::operator()(VariableDeclaration const& _varDecl)
{
if (_varDecl.variables.size() == 1)
setValue(_varDecl.variables.front().name, _varDecl.value.get());
else if (!_varDecl.value)
static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}};
if (!_varDecl.value)
for (auto const& var: _varDecl.variables)
setValue(var.name, nullptr);
setValue(var.name, &zero);
else if (_varDecl.variables.size() == 1)
setValue(_varDecl.variables.front().name, _varDecl.value.get());
}
void SSAValueTracker::setValue(YulString _name, Expression const* _value)
+1 -1
View File
@@ -33,7 +33,7 @@ namespace yul
* Class that walks the AST and stores the initial value of each variable
* that is never assigned to.
*
* Default value is represented as nullptr.
* A special zero constant expression is used for the default value of variables.
*
* Prerequisite: Disambiguator
*/