From 767e01ec2c63b8c719bcc62f874869370d32aeea Mon Sep 17 00:00:00 2001 From: Josselin Date: Fri, 7 Dec 2018 10:38:56 +0000 Subject: [PATCH] Dominator: corner case if there is a if without else for dominance frontier add phi_callback for state variable --- .../core/dominators/node_dominator_tree.py | 37 +++++++++++++++++ slither/slithir/operations/phi_callback.py | 41 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 slither/core/dominators/node_dominator_tree.py create mode 100644 slither/slithir/operations/phi_callback.py diff --git a/slither/core/dominators/node_dominator_tree.py b/slither/core/dominators/node_dominator_tree.py new file mode 100644 index 000000000..046acc439 --- /dev/null +++ b/slither/core/dominators/node_dominator_tree.py @@ -0,0 +1,37 @@ +''' + Nodes of the dominator tree +''' + +from slither.core.children.child_function import ChildFunction + +class DominatorNode(object): + + def __init__(self): + self._succ = set() + self._nodes = [] + + def add_node(self, node): + self._nodes.append(node) + + def add_successor(self, succ): + self._succ.add(succ) + + @property + def cfg_nodes(self): + return self._nodes + + @property + def sucessors(self): + ''' + Returns: + dict(Node) + ''' + return self._succ + +class DominatorTree(ChildFunction): + + def __init__(self, entry_point): + super(DominatorTree, self).__init__() + + + diff --git a/slither/slithir/operations/phi_callback.py b/slither/slithir/operations/phi_callback.py new file mode 100644 index 000000000..ba30088a7 --- /dev/null +++ b/slither/slithir/operations/phi_callback.py @@ -0,0 +1,41 @@ +import logging + +from slither.core.variables.variable import Variable +from slither.slithir.variables import TupleVariable +from slither.core.declarations.function import Function +from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue +from .phi import Phi + +class PhiCallback(Phi): + + def __init__(self, left_variable, nodes): + assert is_valid_lvalue(left_variable) + assert isinstance(nodes, set) + super(PhiCallback, self).__init__(left_variable, nodes) + + @property + def read(self): + return [self.rvalues] + + @property + def rvalues(self): + return self._rvalues + + @property + def rvalue_no_callback(self): + ''' + rvalue if callback are not considered + ''' + return self._rvalues[0] + + @rvalues.setter + def rvalues(self, vals): + self._rvalues = vals + + + @property + def nodes(self): + return self._nodes + + def __str__(self): + return '{}({}) := \u03D5({})'.format(self.lvalue, self.lvalue.type, [v.ssa_name for v in self._rvalues])