Skip to content

Commit

Permalink
Optimize temporary variable creation by excluding void method calls; f…
Browse files Browse the repository at this point in the history
…ixes #6568.
  • Loading branch information
iamsanjaymalakar committed May 1, 2024
1 parent 842c4d0 commit 2bda24e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.type.TypeKind;
import com.sun.source.tree.MethodInvocationTree;
import org.checkerframework.checker.calledmethods.CalledMethodsTransfer;
import org.checkerframework.checker.mustcall.CreatesMustCallForToJavaExpression;
import org.checkerframework.checker.mustcall.MustCallAnnotatedTypeFactory;
Expand All @@ -17,6 +20,8 @@
import org.checkerframework.dataflow.cfg.node.SwitchExpressionNode;
import org.checkerframework.dataflow.cfg.node.TernaryExpressionNode;
import org.checkerframework.dataflow.expression.JavaExpression;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;

/** The transfer function for the resource-leak extension to the called-methods type system. */
Expand Down Expand Up @@ -138,6 +143,14 @@ public TransferResult<AccumulationValue, AccumulationStore> visitObjectCreation(
*/
public void updateStoreWithTempVar(
TransferResult<AccumulationValue, AccumulationStore> result, Node node) {
// If the node is a void method invocation then do not create temp vars for it.
if (node instanceof MethodInvocationNode) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) node.getTree();
ExecutableElement executableElement = TreeUtils.elementFromUse(methodInvocationTree);
if (ElementUtils.getType(executableElement).getKind() == TypeKind.VOID) {
return;
}
}
// Must-call obligations on primitives are not supported.
if (!TypesUtils.isPrimitiveOrBoxed(node.getType())) {
MustCallAnnotatedTypeFactory mcAtf =
Expand Down

0 comments on commit 2bda24e

Please sign in to comment.