fix argument propagation for .unwrap

pull/1271/head
alpharush 2 years ago
parent 77551209d2
commit ee82e10164
  1. 14
      slither/slithir/convert.py
  2. 2
      tests/ast-parsing/user_defined_value_type/argument-0.8.9.sol

@ -400,6 +400,13 @@ def propagate_type_and_convert_call(result, node):
ins = new_ins
result[idx] = ins
# If there's two consecutive type conversions, keep only the last
# ARG_CALL x call_data = [x]
# TMP_4 = CONVERT x to Fix call_data = []
# TMP_5 = CONVERT TMP_4 to uint192 call_data = [TMP_5]
if isinstance(ins, TypeConversion) and ins.variable in call_data:
call_data.remove(ins.variable)
if isinstance(ins, Argument):
# In case of dupplicate arguments we overwrite the value
# This can happen because of addr.call.value(1).value(2)
@ -429,10 +436,10 @@ def propagate_type_and_convert_call(result, node):
continue
new_ins = propagate_types(ins, node)
# Validate that type was propagated
if isinstance(new_ins, OperationWithLValue):
assert new_ins.lvalue.type
if new_ins:
# Validate that type was propagated
if isinstance(new_ins, OperationWithLValue):
assert new_ins.lvalue.type
if isinstance(new_ins, (list,)):
for new_ins_ in new_ins:
new_ins_.set_node(ins.node)
@ -1682,6 +1689,7 @@ def convert_constant_types(irs):
# TODO: add POP instruction
break
types = [p.type for p in func.parameters]
assert len(types) == len(ir.arguments)
for idx, arg in enumerate(ir.arguments):
t = types[idx]
if isinstance(t, ElementaryType):

@ -11,7 +11,7 @@ contract FixLib {
uint256 y = uint192(Fix.unwrap(x));
return div(y, 1e18);
}
function broken(Fix x) external pure returns (uint256) {
function test(Fix x) external pure returns (uint256) {
return div(uint192(Fix.unwrap(x)), 1e18);
}
}
Loading…
Cancel
Save