Merge branch 'dev-legacy-forloop' into dev

pull/172/head
Josselin 6 years ago
commit 1189014530
  1. 12
      slither/slithir/operations/operation.py
  2. 14
      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")
@ -257,15 +258,27 @@ class FunctionSolc(Function):
# if the loop has a init value /condition or expression
# There is no way to determine that for(a;;) and for(;a;) are different with old solc
if 'attributes' in statement:
attributes = statement['attributes']
if 'initializationExpression' in statement:
if not statement['initializationExpression']:
hasInitExession = False
elif 'initializationExpression' in attributes:
if not attributes['initializationExpression']:
hasInitExession = False
if 'condition' in statement:
if not statement['condition']:
hasCondition = False
elif 'condition' in attributes:
if not attributes['condition']:
hasCondition = False
if 'loopExpression' in statement:
if not statement['loopExpression']:
hasLoopExpression = False
elif 'loopExpression' in attributes:
if not attributes['loopExpression']:
hasLoopExpression = False
node_startLoop = self._new_node(NodeType.STARTLOOP, statement['src'])
@ -959,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