Skip to content

Commit

Permalink
Track alias analysis on Binary operation
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Jan 9, 2019
1 parent a938c3a commit 60ab8eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions slither/slithir/operations/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions slither/slithir/utils/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 60ab8eb

Please sign in to comment.