-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix decompiler assignment optimization issue #17008 #17120
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
base: jun/decompiler-issue-17087
Are you sure you want to change the base?
fix decompiler assignment optimization issue #17008 #17120
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
c90d427
to
2d404c8
Compare
31332e9
to
1a86009
Compare
2d404c8
to
e6cf841
Compare
1a86009
to
6bacdef
Compare
e6cf841
to
5cc0a94
Compare
6bacdef
to
1d06027
Compare
5cc0a94
to
c60be0d
Compare
1d06027
to
9b9a80d
Compare
c60be0d
to
f7078a2
Compare
9b9a80d
to
8f239c3
Compare
impl AssignTransformer<'_> { | ||
/// Check if an expression is safe to eliminate, assuming its result is never used. | ||
/// [TODO]: refine the rules to consider other side-effect-carrying operations. | ||
fn safe_to_eliminate(&self, exp: &Exp) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this leaves out whole lot of cases: e.g., addition would be considered safe to eliminate (even though it is not), blocks with side-effects would be disregarded.
I wonder if a a better approach would be to have an allow-list for those constructs that are known to be safe: e.g., Value
, LocalVar
, Temporary
, etc. Otherwise, it would lead to subtle bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Using an allow-list is easier to maintain safety. At this stage, the AST is fairly simple: it should not have nested expressions and complex ones like blocks. So, by even just considering Value
, LocalVar
, and Temporary
, the optimization effects should largely remain. Let me try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It matched my expectations.
8f239c3
to
c75710e
Compare
Description
The decompiler optimizes the following pattern
t1 = rhs; ... use(t1)
===>
... use(rhs)
If
t1
is never used (i.e.,use(t1)
does not exist), the decompiler will eliminatet1 = rhs
entirely. This is not safe asrhs
can have side effects (e.g.,rhs
being a function call). This PR fixes this issue by checking ifrhs
carries potential side effects. Currently, it only checks ifrhs
is aCall(Operation::MoveFunction)
orInvoke
.Close issue #17008.
How Has This Been Tested?
Type of Change
Which Components or Systems Does This Change Impact?