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

Correct the logic of dataflow framework. #3414

Merged
merged 6 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ subprojects {

if (project.name.is('dataflow')) {
dependsOn('liveVariableTest')
dependsOn('issue3447Test')
}
}

Expand Down
18 changes: 18 additions & 0 deletions dataflow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@ task liveVariableTest(dependsOn: compileTestJava, group: 'Verification') {
}
}
}

task issue3447Test(dependsOn: compileTestJava, group: 'Verification') {
xingweitian marked this conversation as resolved.
Show resolved Hide resolved
description 'Test issue 3447 test case for backward analysis.'
inputs.file('tests/issue3447/Test.java')
delete('tests/issue3447/Out.txt')
wmdietl marked this conversation as resolved.
Show resolved Hide resolved
delete('tests/issue3447/Test.class')
doLast {
javaexec {
workingDir = 'tests/issue3447'
if (!JavaVersion.current().java9Compatible) {
jvmArgs += "-Xbootclasspath/p:${configurations.javacJar.asPath}"
}
classpath = sourceSets.test.compileClasspath
classpath += sourceSets.test.output
main = 'livevar.LiveVariable'
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ protected void addStoreAfter(Block pred, @Nullable Node node, S s, boolean addBl
(exceptionStore != null) ? exceptionStore.leastUpperBound(s) : s;
if (!newExceptionStore.equals(exceptionStore)) {
exceptionStores.put(ebPred, newExceptionStore);
inputs.put(ebPred, new TransferInput<V, S>(node, this, newExceptionStore));
addBlockToWorklist = true;
}
}
Expand Down Expand Up @@ -344,7 +345,8 @@ public S runAnalysisFor(
if (n == node && !before) {
return store.getRegularStore();
}
// Copy the store to preserve to change the state in {@link #inputs}
// Copy the store to avoid changing other blocks' transfer inputs in
// {@link #inputs}
TransferResult<V, S> transferResult =
callTransferFunction(n, store.copy());
if (n == node) {
Expand All @@ -370,8 +372,10 @@ public S runAnalysisFor(
return transferInput.getRegularStore();
}
setCurrentNode(node);
// Copy the store to avoid changing other blocks' transfer inputs in {@link
// #inputs}
TransferResult<V, S> transferResult =
callTransferFunction(node, transferInput);
callTransferFunction(node, transferInput.copy());
// Merge transfer result with the exception store of this exceptional block
S exceptionStore = exceptionStores.get(eb);
return exceptionStore == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ public S runAnalysisFor(
if (cache != null && cache.containsKey(n)) {
transferResult = cache.get(n);
} else {
// Copy the store to preserve to change the state in the cache
// Copy the store to avoid changing other blocks' transfer inputs in
// {@link #inputs}
transferResult = callTransferFunction(n, store.copy());
if (cache != null) {
cache.put(n, transferResult);
Expand Down Expand Up @@ -312,8 +313,10 @@ public S runAnalysisFor(
return transferInput.getRegularStore();
}
setCurrentNode(node);
// Copy the store to avoid changing other blocks' transfer inputs in {@link
// #inputs}
TransferResult<V, S> transferResult =
callTransferFunction(node, transferInput);
callTransferFunction(node, transferInput.copy());
return transferResult.getRegularStore();
}
default:
Expand Down
12 changes: 12 additions & 0 deletions dataflow/tests/issue3447/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Test case for Issue 3447:
// https://github.com/typetools/checker-framework/issues/3447

public class Test {
wmdietl marked this conversation as resolved.
Show resolved Hide resolved
public void test() throws Exception {
try {
int[] myNumbers = {1};
System.out.println(myNumbers[1]);
} catch (Exception e) {
}
}
}