From 60ab8eb105bd0565321fe7da41460158acf61756 Mon Sep 17 00:00:00 2001 From: Josselin Date: Wed, 9 Jan 2019 10:25:31 +0000 Subject: [PATCH] Track alias analysis on Binary operation --- slither/slithir/operations/binary.py | 10 ++++++++++ slither/slithir/utils/ssa.py | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/slither/slithir/operations/binary.py b/slither/slithir/operations/binary.py index 95097764f3..6a4269b5dd 100644 --- a/slither/slithir/operations/binary.py +++ b/slither/slithir/operations/binary.py @@ -3,6 +3,7 @@ from slither.core.variables.variable import Variable from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue from slither.core.solidity_types import ElementaryType +from slither.slithir.variables import ReferenceVariable logger = logging.getLogger("BinaryOperationIR") @@ -165,6 +166,15 @@ def type_str(self): return BinaryType.str(self._type) def __str__(self): + if isinstance(self.lvalue, ReferenceVariable): + points = self.lvalue.points_to + while isinstance(points, ReferenceVariable): + points = points.points_to + return '{}(-> {}) = {} {} {}'.format(str(self.lvalue), + points, + self.variable_left, + self.type_str, + self.variable_right) return '{}({}) = {} {} {}'.format(str(self.lvalue), self.lvalue.type, self.variable_left, diff --git a/slither/slithir/utils/ssa.py b/slither/slithir/utils/ssa.py index 32a5ad3951..98fd990e2b 100644 --- a/slither/slithir/utils/ssa.py +++ b/slither/slithir/utils/ssa.py @@ -152,7 +152,7 @@ def update_lvalue(new_ir, node, local_variables_instances, all_local_variables_i if isinstance(new_ir, OperationWithLValue): lvalue = new_ir.lvalue update_through_ref = False - if isinstance(new_ir, Assignment): + if isinstance(new_ir, (Assignment, Binary)): if isinstance(lvalue, ReferenceVariable): update_through_ref = True while isinstance(lvalue, ReferenceVariable): @@ -275,7 +275,7 @@ def generate_ssa_irs(node, local_variables_instances, all_local_variables_instan # rvalues are fixed in solc_parsing.declaration.function node.add_ssa_ir(phi_ir) - if isinstance(new_ir, Assignment): + if isinstance(new_ir, (Assignment, Binary)): if isinstance(new_ir.lvalue, LocalIRVariable): if new_ir.lvalue.is_storage: if isinstance(new_ir.rvalue, ReferenceVariable): @@ -315,7 +315,7 @@ def fix_phi_rvalues_and_storage_ref(node, local_variables_instances, all_local_v l = [item for sublist in l for item in sublist] ir.lvalue.refers_to = set(l) - if isinstance(ir, Assignment): + if isinstance(ir, (Assignment, Binary)): if isinstance(ir.lvalue, ReferenceVariable): origin = ir.lvalue.points_to_origin