Skip to content

Commit

Permalink
Merge pull request goblint#1377 from goblint/issue_1376
Browse files Browse the repository at this point in the history
Fix `evalbinop_base` for `==` on `Int` and `Address`
  • Loading branch information
michael-schwarz authored Mar 4, 2024
2 parents 9c2c167 + fd63de3 commit a119f3f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,26 @@ struct
| Address p, Int n
| Int n, Address p when op=Eq || op=Ne ->
let ik = Cilfacade.get_ikind t in
Int (match ID.to_bool n, AD.to_bool p with
| Some a, Some b -> ID.of_bool ik (op=Eq && a=b || op=Ne && a<>b)
| _ -> bool_top ik)
let res =
if AD.is_null p then
match ID.equal_to Z.zero n with
| `Neq ->
(* n is definitely not 0, p is NULL *)
ID.of_bool ik (op = Ne)
| `Eq ->
(* n is zero, p is NULL*)
ID.of_bool ik (op = Eq)
| _ -> bool_top ik
else if AD.is_not_null p then
match ID.equal_to Z.zero n with
| `Eq ->
(* n is zero, p is not NULL *)
ID.of_bool ik (op = Ne)
| _ -> bool_top ik
else
bool_top ik
in
Int res
| Address p, Int n ->
addToAddrOp p n
| Address p, Top ->
Expand Down
13 changes: 13 additions & 0 deletions tests/regression/00-sanity/53-ptr-and-int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <goblint.h>
int main ()
{
int x;
int three = 3;

int y = (three == &x);

// &x equaling the constant 3 is exceedingly unlikely
__goblint_check(y == 1); //UNKNOWN!

return 0;
}

0 comments on commit a119f3f

Please sign in to comment.