-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve the order of sons when splitting ternary node #1850
Conversation
The parser tests fail due to this test case in
It seems that the expected CFG is wrong due to the same issue #1846. |
@Troublor I haven't had a chance to investigate this, but your change likely requires updating some of the AST parsing tests which generate CFGs (they're not necessarily correct). If you would make your changes against |
@0xalpharush I have changed the base branch to |
You can delete the old artifacts for the failing : Then to regenerate the artifacts:
Then, add the updated artifacts to git. At first glance, I think the update is right. The current CFG seems to incorrect point 14 - True -> 16, 14 - False -> 26 and that's correctly reversed in the new CFG. |
Thanks for the guideline. I have updated the test artifacts, and the tests seem to be all passing. |
Great catch and fix @Troublor. Nice addition to |
Fix #1846
The order of sons of node matters.
Node with
NodeType.IF
relies on the order of the sons to determine which son is the true branch and which is the false branch.However, the
_split_ternary_node
function during AST parsing does not preserve the son order of the father node.slither/slither/solc_parsing/declarations/function.py
Lines 1397 to 1400 in 0ec4874
When the father node is a node with multiple sons, and the index of the son to remove is not
-1
, the order of sones in the father node will be changed afterremove_son
andadd_son
.As a result, the issue in #1846 occurs.
This PR adds a new utility method,
replace_son
, inNode
class to preserve the order of sones when replacing a son.So that #1846 can be fixed.
Two bug-revealing test cases are also added.