Skip to content
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

fix: if-statement CFG construction #23

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions slither/solc_parsing/declarations/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _new_yul_block(

def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
# IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
falseStatement = None
false_body = None

if self.is_compact_ast:
condition = if_statement["condition"]
Expand All @@ -379,13 +379,9 @@ def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
trueStatement = self._parse_statement(
if_statement["trueBody"], condition_node, true_scope
)

if "falseBody" in if_statement and if_statement["falseBody"]:
false_scope = Scope(
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
)
falseStatement = self._parse_statement(
if_statement["falseBody"], condition_node, false_scope
)
false_body = if_statement["falseBody"]
else:
children = if_statement[self.get_children("children")]
condition = children[0]
Expand All @@ -400,19 +396,22 @@ def _parse_if(self, if_statement: Dict, node: NodeSolc) -> NodeSolc:
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
)
trueStatement = self._parse_statement(children[1], condition_node, true_scope)

if len(children) == 3:
false_scope = Scope(
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
)
falseStatement = self._parse_statement(children[2], condition_node, false_scope)
false_body = children[2]

endIf_node = self._new_node(NodeType.ENDIF, if_statement["src"], node.underlying_node.scope)
link_underlying_nodes(trueStatement, endIf_node)

if falseStatement:
if false_body:
false_scope = Scope(
node.underlying_node.scope.is_checked, False, node.underlying_node.scope
)
falseStatement = self._parse_statement(false_body, condition_node, false_scope)
link_underlying_nodes(falseStatement, endIf_node)
else:
link_underlying_nodes(condition_node, endIf_node)

return endIf_node

def _parse_while(self, whilte_statement: Dict, node: NodeSolc) -> NodeSolc:
Expand Down