Add phi origin for state variable at function entry point

pull/87/head
Josselin 6 years ago
parent c345ecd8be
commit 87319a6bff
  1. 2
      slither/slithir/operations/high_level_call.py
  2. 8
      slither/slithir/utils/ssa.py
  3. 2
      slither/solc_parsing/declarations/function.py

@ -69,7 +69,7 @@ class HighLevelCall(Call, OperationWithLValue):
return ret
all_read = [self.destination, self.call_gas, self.call_value] + unroll(self.arguments)
# remove None
return [x for x in all_read if x]
return [x for x in all_read if x] + [self.destination]
@property
def destination(self):

@ -54,8 +54,13 @@ def add_ssa_ir(function, all_state_variables_instances):
for v in function.parameters+function.returns:
if v.name:
init_definition[v.name] = (v, function.entry_point)
add_phi_origins(function.entry_point, init_definition, dict())
for (_, variable_instance) in all_state_variables_instances.items():
if is_used_later(function.entry_point, variable_instance, []):
# rvalues are fixed in solc_parsing.declaration.function
function.entry_point.add_ssa_ir(Phi(StateIRVariable(variable_instance), set()))
add_phi_origins(function.entry_point, init_definition, dict())
for node in function.nodes:
@ -200,6 +205,7 @@ def generate_ssa_irs(node, local_variables_instances, all_local_variables_instan
all_state_variables_instances[variable.canonical_name] = new_var
state_variables_instances[variable.canonical_name] = new_var
phi_ir = PhiCallback(new_var, {node}, new_ir, variable)
# rvalues are fixed in solc_parsing.declaration.function
node.add_ssa_ir(phi_ir)

@ -875,7 +875,7 @@ class FunctionSolc(Function):
def fix_phi_callback(self, last_state_variables_instances):
for node in self.nodes:
for ir in node.irs_ssa:
if isinstance(ir, PhiCallback):
if isinstance(ir, PhiCallback) or node == self.entry_point:
additional = last_state_variables_instances[ir.lvalue.canonical_name]
ir.rvalues = list(set(additional + ir.rvalues))

Loading…
Cancel
Save