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

Avoid duplicating constant assignments to final instance fields #1998

Merged
merged 2 commits into from
Sep 13, 2023
Merged

Avoid duplicating constant assignments to final instance fields #1998

merged 2 commits into from
Sep 13, 2023

Conversation

subarnob
Copy link

@subarnob subarnob commented Sep 6, 2023

Problem

The ConstantValueToInitializerTransformer ensures for instance fields initialized with a default constant value, that constructor implementation(s) have the constant assignment to such instance fields immediately after the call to super constructor. For final instance fields with constant initializers, however, the constant assignment statement is already present in the generated Jimple body of the constructor(s), and furthermore its ordinal position within the body should not matter since they cannot be overwritten. Since the current implementation does not check for this case, a duplicate copy of such constant assignment statements are introduced.
This behavior can affect downstream analyses- e.g., we observe that Tags computed from a liveness analysis are lost when such constant assignment statements are incorrectly duplicated.

Solution

We check for the presence of an existing assignment statement that initializes the given instance field with the given constant value (isInstanceFieldAssignedConstantInBody()), and avoid duplication if present.

  • Note: we observe that these constants are already initialized as expected in the bytecode generated by modern Java compilers and do not know under which circumstances this transformation would be necessary. So, we simply check for the above condition to avoid duplication.

Testing

  • mvn clean verify
  • other internal tests

@StevenArzt StevenArzt merged commit 478c3e4 into soot-oss:develop Sep 13, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants