Skip to content

Commit

Permalink
Continue typechecking dead code. TODO: add an option to disable.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmdietl committed Nov 23, 2023
1 parent 25f7ce8 commit a61489c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ protected boolean commonAssignmentCheck(
/** Case 1: Check for null dereferencing. */
@Override
public Void visitMemberSelect(MemberSelectTree tree, Void p) {
if (atypeFactory.isUnreachable(tree)) {
return super.visitMemberSelect(tree, p);
}
// if (atypeFactory.isUnreachable(tree)) {
// return super.visitMemberSelect(tree, p);
// }
Element e = TreeUtils.elementFromUse(tree);
if (e.getKind() == ElementKind.CLASS) {
if (atypeFactory.containsNullnessAnnotation(null, tree.getExpression())) {
Expand Down
1 change: 1 addition & 0 deletions checker/tests/nullness-initialization/TryCatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void unreachableCatch(String[] xs) {
try {
} catch (Throwable e) {
// Note that this code is dead.
// :: error: (dereference.of.nullable) :: error: (method.invocation.invalid)
t.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5182,9 +5182,9 @@ protected TypeValidator createTypeValidator() {
*/
protected final boolean shouldSkipUses(ExpressionTree exprTree) {
// System.out.printf("shouldSkipUses: %s: %s%n", exprTree.getClass(), exprTree);
if (atypeFactory.isUnreachable(exprTree)) {
return true;
}
// if (atypeFactory.isUnreachable(exprTree)) {
// return true;
// }
Element elm = TreeUtils.elementFromTree(exprTree);
return checker.shouldSkipUses(elm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public void setRoot(@Nullable CompilationUnitTree root) {

super.setRoot(root);
this.scannedClasses.clear();
this.reachableNodes.clear();
// this.reachableNodes.clear();
this.flowResult = null;
this.regularExitStores.clear();
this.exceptionalExitStores.clear();
Expand Down Expand Up @@ -1071,13 +1071,13 @@ public IPair<JavaExpression, String> getExpressionAndOffsetFromJavaExpressionStr
return value != null ? value.getAnnotations().iterator().next() : null;
}

/**
/*
* Returns true if the {@code exprTree} is unreachable. This is a conservative estimate and may
* return {@code false} even though the {@code exprTree} is unreachable.
*
* @param exprTree an expression tree
* @return true if the {@code exprTree} is unreachable
*/
*
public boolean isUnreachable(ExpressionTree exprTree) {
if (!everUseFlow) {
return false;
Expand All @@ -1096,6 +1096,7 @@ public boolean isUnreachable(ExpressionTree exprTree) {
// None of the corresponding nodes is reachable, so this tree is dead.
return true;
}
*/

/**
* Track the state of org.checkerframework.dataflow analysis scanning for each class tree in the
Expand All @@ -1111,15 +1112,15 @@ protected enum ScanState {
/** Map from ClassTree to their dataflow analysis state. */
protected final Map<ClassTree, ScanState> scannedClasses = new HashMap<>();

/**
/*
* A set of trees whose corresponding nodes are reachable. This is not an exhaustive set of
* reachable trees. Use {@link #isUnreachable(ExpressionTree)} instead of this set directly.
*
* <p>This cannot be a set of Nodes, because two LocalVariableNodes are equal if they have the
* same name but represent different uses of the variable. So instead of storing Nodes, it
* stores the result of {@code Node#getTree}.
*/
private final Set<Tree> reachableNodes = new HashSet<>();
// private final Set<Tree> reachableNodes = new HashSet<>();

/**
* The result of the flow analysis. Invariant:
Expand Down Expand Up @@ -1597,13 +1598,15 @@ protected void analyze(
boolean isStatic,
@Nullable Store capturedStore) {
ControlFlowGraph cfg = CFCFGBuilder.build(root, ast, checker, this, processingEnv);
cfg.getAllNodes(this::isIgnoredExceptionType)
.forEach(
node -> {
if (node.getTree() != null) {
reachableNodes.add(node.getTree());
}
});
/*
cfg.getAllNodes(this::isIgnoredExceptionType)
.forEach(
node -> {
if (node.getTree() != null) {
reachableNodes.add(node.getTree());
}
});
*/
if (isInitializationCode) {
Store initStore = !isStatic ? initializationStore : initializationStaticStore;
if (initStore != null) {
Expand Down

0 comments on commit a61489c

Please sign in to comment.