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: deadstore FP where use happens after first return statement #72

Merged
merged 3 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
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
31 changes: 16 additions & 15 deletions amarna/rules/local_rules/DeadStoreRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def code_element_function(self, tree: Tree) -> None:
implicits_and_arguments.append(str(args.children[0]))

defines: Set[Token] = set()
in_return = []
for main_child in tree.children:
if main_child.data != "code_block":
continue
Expand All @@ -62,18 +63,18 @@ def code_element_function(self, tree: Tree) -> None:

# in a return statement, check which variables were not used
for subcode in child.children[0].find_data("code_element_return"):
tokens = [
str(tok) for tok in subcode.scan_values(lambda v: isinstance(v, Token))
]
for dead_store in sorted(defines):
if dead_store in tokens or dead_store in implicits_and_arguments:
continue
sarif = create_result_token(
self.fname,
self.RULE_NAME,
self.RULE_TEXT,
dead_store,
)
if sarif in self.results:
continue
self.results.append(sarif)
for tok in subcode.scan_values(lambda v: isinstance(v, Token)):
in_return.append(str(tok))

for dead_store in sorted(defines):
if dead_store in in_return or dead_store in implicits_and_arguments:
continue
sarif = create_result_token(
self.fname,
self.RULE_NAME,
self.RULE_TEXT,
dead_store,
)
if sarif in self.results:
continue
self.results.append(sarif)
9 changes: 9 additions & 0 deletions tests/dead_store3.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
func are_equal(x, y) -> (eq):
let (a) = 44
if x == y:
return (FALSE)
end
if x == a:
return (TRUE)
end
end
1 change: 1 addition & 0 deletions tests/expected/dead_store3.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[unused-function] in dead_store3.cairo:1:1