Model Object.clone() in PTA for better precision for may-fail-cast
#209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
Object.clone()is modeled viaDefaultNativeModel, which generates a plain return as the method body. This modeling, though general, is not suitable for pointer analysis, as it requires extra level of context-sensitivity to distinguish incoming and outcoming object flows.By modeling
Object.clone()using theIRModelPlugin, we can obtain better precision formay-fail-castwhen analyzing programs context-insensitively.This is because the return type of
clone()the method isjava.lang.Object, and its invocations are often invoked and then cast into the correct type to be used later, as in the following example from jdk17.https://github.com/openjdk/jdk17u/blob/30ef840c3736270330fc0a26849c2456406facfe/src/java.base/share/classes/java/util/IdentityHashMap.java#L704-L713
On five benchmarks (
antlr,bloat,jedit-3.0,columba-1.4, andbriss-0.9from java-benchmarks) we achieve an average reduction of 148 casts that may fail when analyzed context-insensitively, with slightly better precision on other analysis metrics.Diff for master and object-clone-model