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

[CN] Cannot mark preexisting variable as not changing value in a loop #938

Open
peterohanley opened this issue Mar 17, 2025 · 2 comments
Open
Labels
bug Something isn't working cn

Comments

@peterohanley
Copy link

I would like the body of the inner loop to be able to rely on the c it accesses matching the c before it, as well as the c in its own invariant. This was my first attempt:

#include <stdint.h>

void
foo(void)
{
    for(int c = 0; c < 1; ++c)
    /*@ inv 0i32 <= c; c <= 1i32;
    @*/
    {
        int k = c;
        for (int i = 0; i < 1; ++i)
        /*@ inv 0i32 <= i; i <= 1i32;
            0i32 <= c; c < 1i32;
            {&k} unchanged;
            {&c} unchanged;
        @*/
        {
            /*@ assert(k==c);@*/
        }
    }
}

This works:

void
foo3(void)
{
    for(int c = 0; c < 1; ++c)
    /*@ inv 0i32 <= c; c <= 1i32;
    @*/
    {
        int k = c;
        for (int i = 0; i < 1; ++i)
        /*@ inv 0i32 <= i; i <= 1i32;
            0i32 <= c; c < 1i32; // NOTE this is not the same as the outer invariant!
            k == c;
            {&k} unchanged;
            {&c} unchanged;
        @*/
        {
            /*@ assert(k==c);@*/
        }
        /*@ assert(k==c);@*/
    }
}

I think if the unchanged notation allowed {c} unchanged that would fix this.

% cn --version
git-b41bad6f9 [2025-03-13 16:25:31 +0000]
@dc-mak
Copy link
Collaborator

dc-mak commented Mar 19, 2025

Seems related to #913

@dc-mak dc-mak added bug Something isn't working cn labels Mar 19, 2025
@dc-mak
Copy link
Collaborator

dc-mak commented Mar 19, 2025

Please open new issues on www.github.com/rems-project/cn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cn
Projects
None yet
Development

No branches or pull requests

2 participants