- node.ssa_variables_* properties
        - variable.non_ssa_version for StateVariableIR/LocalVariableIR
Fixed:
        - Incorrect SSA conversion on Return IR
        - is_storage property on StateVariableIR/LocalVariableIR
pull/162/head
Josselin 6 years ago
parent 0ff9305aef
commit 59af3887a4
  1. 44
      slither/core/cfg/node.py
  2. 2
      slither/slithir/utils/ssa.py
  3. 12
      slither/slithir/variables/local_variable.py
  4. 10
      slither/slithir/variables/state_variable.py

@ -270,6 +270,29 @@ class Node(SourceMapping, ChildFunction):
""" """
return list(self._solidity_vars_read) return list(self._solidity_vars_read)
@property
def ssa_variables_read(self):
"""
list(Variable): Variables read (local/state/solidity)
"""
return list(self._ssa_vars_read)
@property
def ssa_state_variables_read(self):
"""
list(StateVariable): State variables read
"""
return list(self._ssa_state_vars_read)
@property
def ssa_local_variables_read(self):
"""
list(LocalVariable): Local variables read
"""
return list(self._ssa_local_vars_read)
@property @property
def variables_read_as_expression(self): def variables_read_as_expression(self):
return self._expression_vars_read return self._expression_vars_read
@ -299,6 +322,27 @@ class Node(SourceMapping, ChildFunction):
""" """
return list(self._local_vars_written) return list(self._local_vars_written)
@property
def ssa_variables_written(self):
"""
list(Variable): Variables written (local/state/solidity)
"""
return list(self._ssa_vars_written)
@property
def ssa_state_variables_written(self):
"""
list(StateVariable): State variables written
"""
return list(self._ssa_state_vars_written)
@property
def ssa_local_variables_written(self):
"""
list(LocalVariable): Local variables written
"""
return list(self._ssa_local_vars_written)
@property @property
def variables_written_as_expression(self): def variables_written_as_expression(self):
return self._expression_vars_written return self._expression_vars_written

@ -543,7 +543,7 @@ def copy_ir(ir, local_variables_instances, state_variables_instances, temporary_
lvalue = get_variable(ir, lambda x: ir.lvalue) lvalue = get_variable(ir, lambda x: ir.lvalue)
return Push(array, lvalue) return Push(array, lvalue)
elif isinstance(ir, Return): elif isinstance(ir, Return):
value = get_variable(ir, lambda x: ir.values) value = [get_variable(x, lambda y: y) for x in ir.values]
return Return(value) return Return(value)
elif isinstance(ir, Send): elif isinstance(ir, Send):
destination = get_variable(ir, lambda x: ir.destination) destination = get_variable(ir, lambda x: ir.destination)

@ -24,6 +24,7 @@ class LocalIRVariable(LocalVariable, SlithIRVariable):
# initiate LocalVariable # initiate LocalVariable
self._location = self.location self._location = self.location
self._is_storage = self.is_storage
self._index = 0 self._index = 0
@ -31,6 +32,13 @@ class LocalIRVariable(LocalVariable, SlithIRVariable):
# points to state variables # points to state variables
self._refers_to = set() self._refers_to = set()
# keep un-ssa version
if isinstance(local_variable, LocalIRVariable):
self._non_ssa_version = local_variable.non_ssa_version
else:
self._non_ssa_version = local_variable
self._non_ssa_version = local_variable
@property @property
def index(self): def index(self):
return self._index return self._index
@ -49,6 +57,10 @@ class LocalIRVariable(LocalVariable, SlithIRVariable):
def refers_to(self, variables): def refers_to(self, variables):
self._refers_to = variables self._refers_to = variables
@property
def non_ssa_version(self):
return self._non_ssa_version
def add_refers_to(self, variable): def add_refers_to(self, variable):
# It is a temporaryVariable if its the return of a new .. # It is a temporaryVariable if its the return of a new ..
# ex: string[] memory dynargs = new string[](1); # ex: string[] memory dynargs = new string[](1);

@ -23,6 +23,12 @@ class StateIRVariable(StateVariable, SlithIRVariable):
self._index = 0 self._index = 0
# keep un-ssa version
if isinstance(state_variable, StateIRVariable):
self._non_ssa_version = state_variable.non_ssa_version
else:
self._non_ssa_version = state_variable
@property @property
def index(self): def index(self):
return self._index return self._index
@ -31,6 +37,10 @@ class StateIRVariable(StateVariable, SlithIRVariable):
def index(self, idx): def index(self, idx):
self._index = idx self._index = idx
@property
def non_ssa_version(self):
return self._non_ssa_version
@property @property
def ssa_name(self): def ssa_name(self):
return '{}_{}'.format(self._name, self.index) return '{}_{}'.format(self._name, self.index)

Loading…
Cancel
Save