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

Missing Invariant Checks for Casts #148

Open
DavePearce opened this issue May 10, 2022 · 3 comments
Open

Missing Invariant Checks for Casts #148

DavePearce opened this issue May 10, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@DavePearce
Copy link
Member

Test 000908 reports the wrong error:

type i8 is (int x) where (x >= -128) && (x <= 127)

function f(int x) -> i8[]
requires (x == 0) || (x == 256):
    return [(i8) x]

The error is:

src/main.whiley:5: postcondition may not be satisfied
    return [(i8) x]
    ^^^^^^^^^^^^^^^

But it should be complaining about the cast.

@DavePearce DavePearce added the bug Something isn't working label May 10, 2022
@DavePearce DavePearce changed the title Missing Invariant Checks in Array Initialisers Missing Invariant Checks for Casts May 10, 2022
@DavePearce DavePearce self-assigned this May 10, 2022
@DavePearce
Copy link
Member Author

The essential problem is that its not checking for casts. This should be doable with a little help.

@DavePearce
Copy link
Member Author

The basic problem here is that DefinednessChecker operates of the Boogie AST and evidence of casts has been eliminated.

DavePearce added a commit that referenced this issue May 14, 2022
This puts through fixes for casts.  Everything is getting a bit ugly it would
seem, but that's life :)
@DavePearce
Copy link
Member Author

DavePearce commented May 14, 2022

This example illustrates the problem:

type i8 is (int x) where (x >= -128) && (x <= 127)

function f(int x) -> i8[]
requires (x == 0) || (x == 256):
    return [(i8) x]

The generated Boogie is:

   var t187 : int;
   var x : int;
   x := x#;
   assert nat#is(Int#box(g(HEAP,x)),HEAP);
   $ := g(HEAP,x);
   return;

where we have:

type nat = int;
function nat#inv(n : int, HEAP : [Ref]Any) returns (bool) {
   0 <= n
}
function nat#is(n : Any, HEAP : [Ref]Any) returns (bool) {
   Int#is(n) && nat#inv(Int#unbox(n),HEAP)
}

But this obviously won't pass because this is not strong enough:

function g(HEAP : [Ref]Any, x : int) returns (int);
procedure g(x : int) returns (r : int);
requires Context#Level > 1;
ensures r > 0;
free ensures g(HEAP,x) == r;

Realistically to make this work, I need to fix the boogie backend translation (see #153).

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

No branches or pull requests

1 participant