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

Tracking bit status information in goblint #1153

Closed
edwintorok opened this issue Sep 9, 2023 · 4 comments · Fixed by #1154
Closed

Tracking bit status information in goblint #1153

edwintorok opened this issue Sep 9, 2023 · 4 comments · Fixed by #1154
Assignees
Milestone

Comments

@edwintorok
Copy link
Contributor

edwintorok commented Sep 9, 2023

Maybe I am doing something wrong but the congruence analysis doesn't seem to be able to track this.

Here I am getting a random value, telling goblint to assume the state of the LSB, and then immediately assert it, and goblint says the assertion status is unknown (in a real program of course the assertion would be far away from the assume call):
https://gist.github.com/edwintorok/8c6f3de4f717a3145945705cdcbe863b

(I could attempt to implement an analysis specific to tracking the LSB bit, similar to the sign analysis, but if goblint already has code to handle something similar I'd prefer to reuse or perhaps fix that part. For context: tracking the state of this bit is useful for OCaml C stubs where Is_block() and Is_long() macros check the bit).

@michael-schwarz
Copy link
Member

Thank you, I'll have a look! This should definitely be possible for the congruence domain (after some small tweaks).

@sim642
Copy link
Member

sim642 commented Sep 9, 2023

Besides implementing bitand in the congruence domain, __goblint_assume(x&1) also requires specific changes to BaseInvariant to actually assume that information.

@edwintorok
Copy link
Contributor Author

I tried using modulo (see updated gist), which seems to have some more code, but perhaps needs some improvement too for assume?
BTW I don't have to use assume, if there is another way to tell goblint the status of the low bit I'd be happy to change my code to do that (the goal is to tell goblint that memory allocated by OCaml is aligned to at least 2 bytes or not, when using OCaml integers).

@michael-schwarz
Copy link
Member

What already works on the master branch is if the program is rewritten to explicitly use x % 2 == 1, as in this modified example:

//PARAM: --enable ana.int.congruence --set sem.int.signed_overflow assume_none
#include <goblint.h>

int foo(long x)
{
  __goblint_assume(x%2 == 1);
  __goblint_check(x%2 == 1);
}

int main()
{
  foo(__VERIFIER_nondet_int());
}

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