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

[BUG] CN can't process do-while loops #100

Open
2 of 4 tasks
peterohanley opened this issue Jun 18, 2024 · 4 comments
Open
2 of 4 tasks

[BUG] CN can't process do-while loops #100

peterohanley opened this issue Jun 18, 2024 · 4 comments
Labels
bug Something isn't working CN Issues related to the CN tool

Comments

@peterohanley
Copy link
Collaborator

Summary

CN appears to parse the loop successfully but then fails at a later stage, perhaps in core.

Bug

void f(void)
{
    int x = 0;
    do {x = 1;} while(x == 2);
}
% cn dowhile.c 
dowhile.c:4:5: error: undefined code label
continue_493
    do {x = 1;} while(x == 2);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~ 

Acceptance Criteria

Either confirmation that it is intended behavior or implement this construct in the AST transform to core, or wherever else it should be..

Do

  • assign issue to a Milestone
  • define acceptance criteria
  • add appropriate labels
  • Fix appropriate part of CN, perhaps control flow of core?
@peterohanley peterohanley added bug Something isn't working CN Issues related to the CN tool labels Jun 18, 2024
@cp526
Copy link
Collaborator

cp526 commented Jun 21, 2024

This is fixed by dbadf3e . The syntax for do-while annotations in CN is as below.

void f(void)
{
    int x = 1;
    do 
    /*@ inv x == 1i32; @*/ 
    {
      x = 0;
    } 
    while(x == 1);
}

This is slightly clunky, but having the inv before the loop body makes clear where the invariant has to hold: each time the loop body is entered (whether for the first time, or when re-entering when the loop condition succeeds).

(Putting inv before the do, while cleaner-looking makes the parser grammar ambiguous.)

This is hardly tested so far. In particular, it's not clear yet whether requiring the invariant to hold on each loop entry is what we want for do-while, or whether we'd prefer loop invariants that don't have to hold on the first loop iteration but only when the loop is re-entered. (Closing for now, please re-open if needed.)

@cp526 cp526 closed this as completed Jun 21, 2024
@bcpierce00
Copy link
Collaborator

bcpierce00 commented Jun 21, 2024 via email

@cp526
Copy link
Collaborator

cp526 commented Jun 21, 2024

That's also possible. Is that what one wants for proofs about do-while?

@bcpierce00
Copy link
Collaborator

bcpierce00 commented Jun 21, 2024 via email

@cp526 cp526 reopened this Jul 2, 2024
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 Issues related to the CN tool
Projects
None yet
Development

No branches or pull requests

3 participants