- LocalIRVariable: remove dupplicate non_ssa_version assignment
SSA improvements (fix #156)
        - Add PHI operation on functions' arguments
        - Use reachable_from information to find the PHI rvalues
pull/169/head
Josselin 6 years ago
parent 2d37a03a91
commit 18ad15a577
  1. 7
      slither/slithir/utils/ssa.py
  2. 1
      slither/slithir/variables/local_variable.py
  3. 11
      slither/solc_parsing/declarations/function.py

@ -54,7 +54,12 @@ def add_ssa_ir(function, all_state_variables_instances):
return
init_definition = dict()
for v in function.parameters+function.returns:
for v in function.parameters:
if v.name:
init_definition[v.name] = (v, function.entry_point)
function.entry_point.add_ssa_ir(Phi(LocalIRVariable(v), set()))
for v in function.returns:
if v.name:
init_definition[v.name] = (v, function.entry_point)

@ -37,7 +37,6 @@ class LocalIRVariable(LocalVariable, SlithIRVariable):
self._non_ssa_version = local_variable.non_ssa_version
else:
self._non_ssa_version = local_variable
self._non_ssa_version = local_variable
@property
def index(self):

@ -28,6 +28,8 @@ from slither.visitors.expression.export_values import ExportValues
from slither.visitors.expression.has_conditional import HasConditional
from slither.core.declarations.contract import Contract
from slither.slithir.variables import StateIRVariable, LocalIRVariable, Constant
logger = logging.getLogger("FunctionSolc")
class FunctionSolc(Function):
@ -947,9 +949,18 @@ class FunctionSolc(Function):
for node in self.nodes:
for ir in node.irs_ssa:
if node == self.entry_point:
if isinstance(ir.lvalue, StateIRVariable):
additional = [initial_state_variables_instances[ir.lvalue.canonical_name]]
additional += last_state_variables_instances[ir.lvalue.canonical_name]
ir.rvalues = list(set(additional + ir.rvalues))
# function parameter
else:
# find index of the parameter
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 = [a for a in additional if not isinstance(a, Constant)]
ir.rvalues = list(set(additional + ir.rvalues))
if isinstance(ir, PhiCallback):
callee_ir = ir.callee_ir
if isinstance(callee_ir, InternalCall):

Loading…
Cancel
Save