You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicclassArraySwap {
staticbooleanswap(int[] array, inti, intj) {
inttemp;
if (i < 0 || i >= array.length || j < 0 || j >= array.length) {
returnfalse;
}
temp = array[i];
array[i] = array[j];
array[j] = temp;
returntrue;
}
publicstaticvoidmain(String[] args) {
int[] numberArray = {1, 8, 10};//;1, 8, 8, 8, 10, 10};booleanmustTrue = numberArray[1] == 8;
// test cases "swap only accepts valid positions"booleantest1 = swap(numberArray, 0, 2);
booleantest2 = swap(numberArray, 0, 1);
// the analysis is unsound: it reports true herebooleanmustFalse = numberArray[1] == 8;
// test cases "swap accepts bad positions"booleantest3 = swap(numberArray, 42, 1);
}
}
Interprocedural analysis with Array_bounds computes mustFalse to be true.
Looking at the DAIG of swap, I see that elements of the input array are removed from the abstract memory when the array is modified. And then in the main function, abstract memory remains the same, "forgetting" the fact the array has changed.
[UPD] The DSG is attached.
The text was updated successfully, but these errors were encountered:
I can repro this -- thanks for the test case! That domain should be smarter in how it applies procedure summaries at return sites. It's able to deal with mutation on fields of the receiver but isn't correctly handling mutations on arguments. I'll try to get that ironed out soon when I get the time!
solved_ArraySwap.dsg.zip
Here is a Java version of
bucket_swap.js
from DAI's benchmarks:Interprocedural analysis with
Array_bounds
computesmustFalse
to be true.Looking at the DAIG of
swap
, I see that elements of the input array are removed from the abstract memory when the array is modified. And then in the main function, abstract memory remains the same, "forgetting" the fact the array has changed.[UPD] The DSG is attached.
The text was updated successfully, but these errors were encountered: