Add slithir.operation.unroll as a general util (slither.utils.utils). Use unroll on fix_phi operations

pull/172/head
Josselin 6 years ago
parent 43fa54dde3
commit b539a5f199
  1. 12
      slither/slithir/operations/operation.py
  2. 2
      slither/solc_parsing/declarations/function.py
  3. 8
      slither/utils/utils.py

@ -1,6 +1,7 @@
import abc
from slither.core.context.context import Context
from slither.core.children.child_node import ChildNode
from slither.utils.utils import unroll
class AbstractOperation(abc.ABC):
@ -30,11 +31,6 @@ class Operation(Context, ChildNode, AbstractOperation):
return self.read
# if array inside the parameters
def _unroll(self, l):
ret = []
for x in l:
if not isinstance(x, list):
ret += [x]
else:
ret += self._unroll(x)
return ret
@staticmethod
def _unroll(l):
return unroll(l)

@ -29,6 +29,7 @@ from slither.visitors.expression.has_conditional import HasConditional
from slither.core.declarations.contract import Contract
from slither.slithir.variables import StateIRVariable, LocalIRVariable, Constant
from slither.utils.utils import unroll
logger = logging.getLogger("FunctionSolc")
@ -971,6 +972,7 @@ class FunctionSolc(Function):
idx = self.parameters.index(ir.lvalue.non_ssa_version)
# find non ssa version of that index
additional = [n.ir.arguments[idx] for n in self.reachable_from_nodes]
additional = unroll(additional)
additional = [a for a in additional if not isinstance(a, Constant)]
ir.rvalues = list(set(additional + ir.rvalues))
if isinstance(ir, PhiCallback):

@ -0,0 +1,8 @@
def unroll(l):
ret = []
for x in l:
if not isinstance(x, list):
ret += [x]
else:
ret += unroll(x)
return ret
Loading…
Cancel
Save