Merge pull request #1772 from crytic/Troublor-issue_1748

Fix IR operation when initializing array with one-element array literal
pull/1774/head
Feist Josselin 2 years ago committed by GitHub
commit d12852327d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      slither/visitors/slithir/expression_to_slithir.py
  2. 18
      tests/test_ssa_generation.py

@ -220,6 +220,12 @@ class ExpressionToSlithIR(ExpressionVisitor):
operation.set_expression(expression) operation.set_expression(expression)
self._result.append(operation) self._result.append(operation)
set_val(expression, left) set_val(expression, left)
elif isinstance(left.type, ArrayType):
# Special case for init of array, when the right has only one element
operation = InitArray([right], left)
operation.set_expression(expression)
self._result.append(operation)
set_val(expression, left)
else: else:
operation = convert_assignment( operation = convert_assignment(
left, right, expression.type, expression.expression_return_type left, right, expression.type, expression.expression_return_type

@ -27,6 +27,7 @@ from slither.slithir.operations import (
BinaryType, BinaryType,
InternalCall, InternalCall,
Index, Index,
InitArray,
) )
from slither.slithir.utils.ssa import is_used_later from slither.slithir.utils.ssa import is_used_later
from slither.slithir.variables import ( from slither.slithir.variables import (
@ -1059,3 +1060,20 @@ def test_issue_473():
# return is for second phi # return is for second phi
assert len(return_value.values) == 1 assert len(return_value.values) == 1
assert second_phi.lvalue in return_value.values assert second_phi.lvalue in return_value.values
def test_issue_1748():
source = """
contract Contract {
uint[] arr;
function foo(uint i) public {
arr = [1];
}
}
"""
with slither_from_source(source) as slither:
c = slither.get_contract_from_name("Contract")[0]
f = c.functions[0]
operations = f.slithir_operations
assign_op = operations[0]
assert isinstance(assign_op, InitArray)

Loading…
Cancel
Save