Skip to content

Unsound interprocedural Array_bounds analysis when array is modified #9

@julbinb

Description

@julbinb

solved_ArraySwap.dsg.zip
Here is a Java version of bucket_swap.js from DAI's benchmarks:

public class ArraySwap {
    static boolean swap(int[] array, int i, int j) {
        int temp;
        if (i < 0 || i >= array.length || j < 0 || j >= array.length) {
            return false;
        }
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
        return true;
    }
    
    public static void main(String[] args) {
        int[] numberArray = {1, 8, 10};//;1, 8, 8, 8, 10, 10};
        boolean mustTrue = numberArray[1] == 8;
        
        // test cases "swap only accepts valid positions"
        boolean test1 = swap(numberArray, 0, 2);
        boolean test2 = swap(numberArray, 0, 1);
        
        // the analysis is unsound: it reports true here
        boolean mustFalse = numberArray[1] == 8;
        
        // test cases "swap accepts bad positions"
        boolean test3 = 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions