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

Merge stores after every expression statement #159

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions checker/tests/regex/Issue3281.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Test case for Issue 3281:
// https://github.com/typetools/checker-framework/issues/3281

import java.util.regex.Pattern;
import org.checkerframework.checker.regex.RegexUtil;

public class Issue3281 {

void bar(String s) {
RegexUtil.isRegex(s);
if (true) {
// :: error: (argument.type.incompatible)
Pattern.compile(s);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,9 @@ protected static class CFGTranslationPhaseOne extends TreePathScanner<Node, Void
*/
protected final List<LambdaExpressionTree> declaredLambdas;

/** Statements in a method that are followed by if-statement. */
protected final HashSet<StatementTree> statementBeforeIf;

/**
* @param treeBuilder builder for new AST nodes
* @param annotationProvider extracts annotations from AST nodes
Expand Down Expand Up @@ -1655,6 +1658,7 @@ public CFGTranslationPhaseOne(
returnNodes = new ArrayList<>();
declaredClasses = new ArrayList<>();
declaredLambdas = new ArrayList<>();
statementBeforeIf = new HashSet<>();
}

/**
Expand Down Expand Up @@ -3616,7 +3620,16 @@ public Node visitErroneous(ErroneousTree tree, Void p) {

@Override
public Node visitExpressionStatement(ExpressionStatementTree tree, Void p) {
return scan(tree.getExpression(), p);
// For every expression statement, create a local variable and assign the expression to
// that local variable, which would lead to merging of the two stores during dataflow
// analysis.
String name = uniqueName("mergeStoreBeforeIf");
Element owner = findOwner();
ExpressionTree initializer = tree.getExpression();
VariableTree auxillaryVariable =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this auxillary a typo? Should it be auxiliary?

treeBuilder.buildVariableDecl(
TreeUtils.typeOf(initializer), name, owner, initializer);
return scan(auxillaryVariable, p);
}

@Override
Expand Down