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

Iterating over struct elements #848

Open
lwli11 opened this issue Feb 4, 2025 · 0 comments
Open

Iterating over struct elements #848

lwli11 opened this issue Feb 4, 2025 · 0 comments
Labels

Comments

@lwli11
Copy link

lwli11 commented Feb 4, 2025

Is there a possible way to write the annotations so this verifies?

Basically, I want to iterate over a list of structs, and then the internal array within the struct.

typedef struct {
        int size; // Number in cluster
        char* chars; // Array in cluster
} cluster_t;

void tester(cluster_t* clusters)
        /*@
          requires take c = each(u64 j; 0u64 <= j && j < 10u64) { Owned<cluster_t>(array_shift<cluster_t>(clusters,j)) };
          ensures take c2= each(u64 j; 0u64 <= j && j < 10u64) { Owned<cluster_t>(array_shift<cluster_t>(clusters,j)) };

          @*/
{
        for (int k=0; k<10; k++)
                /*@
                  inv take c4=  each(u64 j; 0u64 <= j && j < 10u64) { Owned<cluster_t>(array_shift<cluster_t>(clusters,j)) };
                  {clusters} unchanged;
                  @*/
                if (k>=0 && k<10){
                        /*@ extract Owned<cluster_t>, (u64) k; @*/
                        cluster_t cluster = clusters[k];
                        if (cluster.size>=0){
                                {
                                        for (int i=0; i<cluster.size; i++)
                                                /*@
                                                  inv take c3 =  each(u64 j; 0u64 <= j && j < 10u64) { Owned<cluster_t>(array_shift<cluster_t>(clusters,j)) };
                                                  take cl2 = Owned<cluster_t>(&cluster);
                                                  cluster.size>=0i32; cluster.size <=MAXi32();

                                                  take cc =  each(u64 j; 0u64 <= j && j < (u64) cluster.size) { Owned<char>(array_shift<char>(cluster.chars,j)) };
                                                  {&cluster} unchanged;
                                                  {clusters} unchanged;
                                                  @*/
                                        {
                                                if (i>=0 && i< cluster.size){
                                                        /*@ extract Owned<char>, (u64) i; @*/
                                                        char c = cluster.chars[i];
                                                }
                                        }
                                }
                        }
                }
}
@ZippeyKeys12 ZippeyKeys12 added the cn label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants