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

Verifying D programs #788

Open
roxanaRA opened this issue Apr 7, 2022 · 0 comments
Open

Verifying D programs #788

roxanaRA opened this issue Apr 7, 2022 · 0 comments

Comments

@roxanaRA
Copy link

roxanaRA commented Apr 7, 2022

Hello,

I am working on a project to verify D programs and I am using Smack.
I created a template for loop invariants in D and I wanted to use Smack with it. The following is an example:

mixin template LoopInvariant() {
    void call_invariant(T...)(T params) {

        static if (params.length == 3) {
            for(int k = params[0]; k < params[1]; k++)
                        params[2](k);
        }
    }
}

int getMaxIndex(int[] array, int n) {
    int i = 0;
    int index = 0;

    while (i < n) {

        /* I want to replace this with my template  
        for(int k = 0; k < i; k++) {
            __VERIFIER_assert(array[k] <= array[index]); 
        }*/
        
        mixin LoopInvariant!();
        call_invariant(0, i, ((int k) => __VERIFIER_assert(array[k] <= array[index])));

        if (array[i] > array[index])
            index = i;
        i = i + 1;

    }

    return index;
}

The code with the for loop worked fine with Smack.
I want to replace the commented for loop with my template.
This construction worked in D with D assert at runtime, however when I try it with Smack and __VERIFIER_assert the assert is always false.

Regarding this problem, I tried an easier example:

void foo() {
int index = 12345;

mixin LoopInvariant!();
call_invariant(0, 1, ((int k) => __VERIFIER_assert(k < index)));
}

Looking at the Boogie code I found out that the index variable outside the lambda call and the index variable inside the lambda function are in different memories locations.
In D, at runtime, the index from the lambda function can be inferred as the one from outside it. I was wondering if this inference can be added into Smack?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant