soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.85k stars 706 forks source link

Avoid duplicating constant assignments to final instance fields #1998

Closed subarnob closed 12 months ago

subarnob commented 1 year ago

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.

Testing