Skip to content

Commit

Permalink
Merge pull request #1506 from goblint/apron-compare-fix
Browse files Browse the repository at this point in the history
Fix Apron `compare` function usage
  • Loading branch information
sim642 authored Jul 8, 2024
2 parents 502cf9f + 852a453 commit 8f0301f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Goblint includes analyses for assertions, overflows, deadlocks, etc and can be e
conf-gcc ; ensures opam-repository CI installs real gcc from homebrew on MacOS
)
(depopts
apron
(apron (>= v0.9.15))
z3
)
(conflicts
Expand Down
5 changes: 4 additions & 1 deletion goblint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ depends: [
"benchmark" {with-test}
"conf-gcc"
]
depopts: ["apron" "z3"]
depopts: [
"apron" {>= "v0.9.15"}
"z3"
]
conflicts: [
"result" {< "1.5"}
"ez-conf-lib" {= "1"}
Expand Down
2 changes: 1 addition & 1 deletion goblint.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ doc: "https://goblint.readthedocs.io/en/latest/"
bug-reports: "https://github.com/goblint/analyzer/issues"
depends: [
"angstrom" {= "0.15.0"}
"apron" {= "v0.9.14~beta.2"}
"apron" {= "v0.9.15"}
"arg-complete" {= "0.1.0"}
"astring" {= "0.8.5"}
"base-bigarray" {= "base"}
Expand Down
4 changes: 2 additions & 2 deletions src/cdomains/apron/affineEqualityDomain.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct
let meet t1 t2 = timing_wrap "meet" (meet t1) t2

let leq t1 t2 =
let env_comp = Environment.compare t1.env t2.env in (* Apron's Environment.compare has defined return values. *)
let env_comp = Environment.cmp t1.env t2.env in (* Apron's Environment.cmp has defined return values. *)
if env_comp = -2 || env_comp > 0 then
(* -2: environments are not compatible (a variable has different types in the 2 environements *)
(* -1: if env1 is a subset of env2, (OK) *)
Expand Down Expand Up @@ -334,7 +334,7 @@ struct
else
match Option.get a.d, Option.get b.d with
| x, y when is_top_env a || is_top_env b -> {d = Some (Matrix.empty ()); env = Environment.lce a.env b.env}
| x, y when (Environment.compare a.env b.env <> 0) ->
| x, y when (Environment.cmp a.env b.env <> 0) ->
let sup_env = Environment.lce a.env b.env in
let mod_x = dim_add (Environment.dimchange a.env sup_env) x in
let mod_y = dim_add (Environment.dimchange b.env sup_env) y in
Expand Down
6 changes: 3 additions & 3 deletions src/cdomains/apron/apronDomain.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ struct
let hash (x:t) =
A.hash Man.mgr x

let compare (x:t) y: int =
(* there is no A.compare, but polymorphic compare should delegate to Abstract0 and Environment compare's implemented in Apron's C *)
Stdlib.compare x y
let compare (x: t) (y: t): int =
failwith "Apron.Abstract1 doesn't have total order" (* https://github.com/antoinemine/apron/issues/99 *)

let printXml f x = BatPrintf.fprintf f "<value>\n<map>\n<key>\nconstraints\n</key>\n<value>\n%s</value>\n<key>\nenv\n</key>\n<value>\n%s</value>\n</map>\n</value>\n" (XmlUtil.escape (Format.asprintf "%a" A.print x)) (XmlUtil.escape (Format.asprintf "%a" (Environment.print: Format.formatter -> Environment.t -> unit) (A.env x)))

let to_yojson (x: t) =
Expand Down
8 changes: 7 additions & 1 deletion src/cdomains/apron/gobApron.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ struct
include Lincons1

let show = Format.asprintf "%a" print
let compare x y = String.compare (show x) (show y) (* HACK *)
let compare x y =
(* TODO: implement proper total Lincons1 order *)
String.compare (show x) (show y) (* HACK *)

let num_vars x =
(* Apron.Linexpr0.get_size returns some internal nonsense, so we count ourselves. *)
Expand Down Expand Up @@ -49,6 +51,10 @@ module Environment =
struct
include Environment

let compare (x: t) (y: t): int =
(* TODO: implement total Environment order in OCaml *)
failwith "Apron.Environment doesn't have total order" (* https://github.com/antoinemine/apron/issues/99 *)

let ivars_only env =
let ivs, fvs = Environment.vars env in
assert (Array.length fvs = 0); (* shouldn't ever contain floats *)
Expand Down
4 changes: 2 additions & 2 deletions src/cdomains/apron/linearTwoVarEqualityDomain.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ struct
let meet t1 t2 = timing_wrap "meet" (meet t1) t2

let leq t1 t2 =
let env_comp = Environment.compare t1.env t2.env in (* Apron's Environment.compare has defined return values. *)
let env_comp = Environment.cmp t1.env t2.env in (* Apron's Environment.cmp has defined return values. *)
let implies ts i (var, offs, divi) =
let tuple_cmp = Tuple3.eq (Option.eq ~eq:(Tuple2.eq (Z.equal) (Int.equal))) (Z.equal) (Z.equal) in
match var with
Expand Down Expand Up @@ -543,7 +543,7 @@ struct
| Some x, Some y when is_top a || is_top b ->
let new_env = Environment.lce a.env b.env in
top_of new_env
| Some x, Some y when (Environment.compare a.env b.env <> 0) ->
| Some x, Some y when (Environment.cmp a.env b.env <> 0) ->
let sup_env = Environment.lce a.env b.env in
let mod_x = dim_add (Environment.dimchange a.env sup_env) x in
let mod_y = dim_add (Environment.dimchange b.env sup_env) y in
Expand Down

0 comments on commit 8f0301f

Please sign in to comment.