Skip to content

Commit 0dcc2c8

Browse files
committed
Abstract Invariant.exp
1 parent 0f1d8a1 commit 0dcc2c8

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/cdomain/value/domains/invariant.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ struct
2424
let narrow = meet
2525
end
2626

27+
type exp = GoblintCil.exp (* This is abstract in the interface because invariant expressions may be optimized for readability but lack implicit casts, etc, which are required to normally use CIL exp-s in Goblint. *)
28+
let show_exp = ExpLat.show
29+
let exp_to_cil = Fun.id
30+
2731
module ES = SetDomain.Make (ExpLat)
2832

2933
(* Turns an expression into alist of conjuncts, pulling out common conjuncts from top-level disjunctions *)

src/cdomain/value/domains/invariant.mli

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
(** Invariants for witnesses. *)
22

3-
include Lattice.S with type t = [ `Bot | `Lifted of GoblintCil.exp | `Top ]
3+
type exp
4+
val show_exp: exp -> string
5+
val exp_to_cil: exp -> GoblintCil.exp
6+
(** Breaks abstraction, only for use in {!EvalAssert}! *)
47

5-
val process_exp: GoblintCil.exp -> GoblintCil.exp list
8+
include Lattice.S with type t = [ `Bot | `Lifted of exp | `Top ]
9+
10+
val process_exp: exp -> exp list
611

712
val none: t
813
val of_exp: GoblintCil.exp -> t

src/transform/evalAssert.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct
6161
match (ask ~node loc).f (Queries.Invariant context) with
6262
| `Lifted e ->
6363
let es = Invariant.process_exp e in
64-
let asserts = List.map (fun e -> cInstr ("%v:assert (%e:exp);") loc [("assert", Fv assert_function); ("exp", Fe e)]) es in
64+
let asserts = List.map (fun e -> cInstr ("%v:assert (%e:exp);") loc [("assert", Fv assert_function); ("exp", Fe (Invariant.exp_to_cil e))]) es in
6565
if surroundByAtomic then
6666
let abegin = (cInstr ("%v:__VERIFIER_atomic_begin();") loc [("__VERIFIER_atomic_begin", Fv atomicBegin)]) in
6767
let aend = (cInstr ("%v:__VERIFIER_atomic_end();") loc [("__VERIFIER_atomic_end", Fv atomicEnd)]) in

src/witness/yamlWitness.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ struct
295295
let location = Entry.location ~location:loc ~location_function in
296296
let invs = Invariant.process_exp inv in
297297
List.fold_left (fun acc inv ->
298-
let invariant = CilType.Exp.show inv in
298+
let invariant = Invariant.show_exp inv in
299299
let invariant = Entry.location_invariant ~location ~invariant in
300300
incr cnt_location_invariant;
301301
invariant :: acc
@@ -325,7 +325,7 @@ struct
325325
let location = Entry.location ~location:loc ~location_function in
326326
let invs = Invariant.process_exp inv in
327327
List.fold_left (fun acc inv ->
328-
let invariant = CilType.Exp.show inv in
328+
let invariant = Invariant.show_exp inv in
329329
let invariant = Entry.loop_invariant ~location ~invariant in
330330
incr cnt_loop_invariant;
331331
invariant :: acc
@@ -351,15 +351,15 @@ struct
351351
| `Lifted inv, "invariant_set-flow_insensitive_invariant" ->
352352
let invs = Invariant.process_exp inv in
353353
List.fold_left (fun acc inv ->
354-
let invariant = CilType.Exp.show inv in
354+
let invariant = Invariant.show_exp inv in
355355
let invariant = Entry.flow_insensitive_invariant ~invariant in
356356
incr cnt_flow_insensitive_invariant;
357357
invariant :: acc
358358
) acc invs
359359
| `Lifted inv, "invariant_set-location_invariant" ->
360360
(* TODO: fold_flow_insensitive_as_location is now only used here, inline/move? *)
361361
fold_flow_insensitive_as_location ~inv (fun ~location ~inv acc ->
362-
let invariant = CilType.Exp.show inv in
362+
let invariant = Invariant.show_exp inv in
363363
let invariant = Entry.location_invariant ~location ~invariant in
364364
incr cnt_location_invariant;
365365
invariant :: acc

0 commit comments

Comments
 (0)