Skip to content

Commit 0c296a9

Browse files
committed
Use Queries.eval_bool elsewhere
1 parent 3eaa7f5 commit 0c296a9

File tree

6 files changed

+39
-56
lines changed

6 files changed

+39
-56
lines changed

src/analyses/abortUnless.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ struct
3030
if man.local then
3131
match f.sformals with
3232
| [arg] when isIntegralType arg.vtype ->
33-
(match man.ask (EvalInt (Lval (Var arg, NoOffset))) with (* TODO: Queries.eval_bool? *)
34-
| v when Queries.ID.is_bot v -> false
35-
| v ->
36-
match Queries.ID.to_bool v with
37-
| Some b -> b
38-
| None -> false)
33+
(match Queries.eval_bool (Analyses.ask_of_man man) (Lval (Var arg, NoOffset)) with
34+
| `Bot -> false
35+
| `Lifted b -> b
36+
| `Top -> false)
3937
| _ ->
4038
(* should not happen, man.local should always be false in this case *)
4139
false

src/analyses/memLeak.ml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,16 @@ struct
228228
warn_for_multi_threaded_due_to_abort man;
229229
state
230230
| Assert { exp; refine = true; _ } ->
231-
begin match man.ask (Queries.EvalInt exp) with (* TODO: Queries.eval_bool? *)
232-
| a when Queries.ID.is_bot a -> M.warn ~category:Assert "assert expression %a is bottom" d_exp exp
233-
| a ->
234-
begin match Queries.ID.to_bool a with
235-
| Some true -> ()
236-
| Some false ->
237-
(* If we know for sure that the expression in "assert" is false => need to check for memory leaks *)
238-
warn_for_multi_threaded_due_to_abort man;
239-
check_for_mem_leak man
240-
| None ->
241-
warn_for_multi_threaded_due_to_abort man;
242-
check_for_mem_leak man ~assert_exp_imprecise:true ~exp:(Some exp)
243-
end
231+
begin match Queries.eval_bool (Analyses.ask_of_man man) exp with
232+
| `Bot -> M.warn ~category:Assert "assert expression %a is bottom" d_exp exp
233+
| `Lifted true -> ()
234+
| `Lifted false ->
235+
(* If we know for sure that the expression in "assert" is false => need to check for memory leaks *)
236+
warn_for_multi_threaded_due_to_abort man;
237+
check_for_mem_leak man
238+
| `Top ->
239+
warn_for_multi_threaded_due_to_abort man;
240+
check_for_mem_leak man ~assert_exp_imprecise:true ~exp:(Some exp)
244241
end;
245242
state
246243
| ThreadExit _ ->

src/analyses/unassumeAnalysis.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct
261261
let e = List.fold_left (fun a {exp = b; _} -> Cil.(BinOp (LAnd, a, b, intType))) x.exp xs in
262262
M.info ~category:Witness "unassume invariant: %a" CilType.Exp.pretty e;
263263
if not !AnalysisState.postsolving then (
264-
if not (GobConfig.get_bool "ana.unassume.precheck" && Queries.ID.to_bool (man.ask (EvalInt e)) = Some false) then ( (* TODO: Queries.eval_bool? *)
264+
if not (GobConfig.get_bool "ana.unassume.precheck" && Queries.eval_bool (Analyses.ask_of_man man) e = `Lifted false) then (
265265
let tokens = x.token :: List.map (fun {token; _} -> token) xs in
266266
man.emit (Unassume {exp = e; tokens});
267267
List.iter WideningTokenLifter.add tokens
@@ -280,9 +280,8 @@ struct
280280
let body man fd =
281281
let pres = FH.find_all fun_pres fd in
282282
let st = List.fold_left (fun acc pre ->
283-
let v = man.ask (EvalInt pre) in (* TODO: Queries.eval_bool? *)
284283
(* M.debug ~category:Witness "%a precondition %a evaluated to %a" CilType.Fundec.pretty fd CilType.Exp.pretty pre Queries.ID.pretty v; *)
285-
if Queries.ID.to_bool v = Some true then
284+
if Queries.eval_bool (Analyses.ask_of_man man) pre = `Lifted true then
286285
D.add pre acc
287286
else
288287
acc

src/domains/queries.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ let may_be_less = eval_int_binop (module MayBool) Lt
559559
let eval_bool (ask: ask) e: BoolDomain.FlatBool.t =
560560
let e' = CastE (TInt (IBool, []), e) in
561561
match ask.f (EvalInt e') with
562-
| v when ID.is_bot v -> `Bot
562+
| v when ID.is_bot v || ID.is_bot_ikind v -> `Bot
563563
| v ->
564564
match ID.to_bool v with
565565
| Some b -> `Lifted b

src/transform/expressionEvaluation.ml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,10 @@ struct
125125
value_after
126126

127127
method private try_ask location expression =
128-
match ~? (fun () -> (ask location).Queries.f (Queries.EvalInt expression)) with (* TODO: Queries.eval_bool? *)
129-
(* Inapplicable: Unreachable *)
130-
| Some x when Queries.ID.is_bot_ikind x -> None
131-
| Some x ->
132-
begin match Queries.ID.to_int x with
133-
(* Evaluable: Definite *)
134-
| Some i -> Some (Some (not (Z.equal i Z.zero)))
135-
(* Evaluable: Inconclusive *)
136-
| None -> Some None
137-
end
128+
match ~? (fun () -> Queries.eval_bool (ask location) expression) with
129+
| Some `Bot -> None (* Inapplicable: Unreachable *)
130+
| Some (`Lifted b) -> Some (Some b) (* Evaluable: Definite *)
131+
| Some `Top -> Some None (* Evaluable: Inconclusive *)
138132
(* Inapplicable: Unlisted *)
139133
| None
140134
| exception Not_found -> None

src/witness/yamlWitness.ml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,15 @@ struct
454454
| `Lifted c_inv ->
455455
(* Collect all start states that may satisfy the invariant of current_c *)
456456
List.iter (fun c ->
457-
let x = R.ask_local (c.node, c.context) ~local:c.state (Queries.EvalInt c_inv) in (* TODO: Queries.eval_bool? *)
458-
if Queries.ID.is_bot x || Queries.ID.is_bot_ikind x then (* dead code *)
457+
match Queries.eval_bool {f = (fun (type a) (q: a Queries.t) -> R.ask_local (c.node, c.context) ~local:c.state q)} c_inv with
458+
| `Bot -> (* dead code *)
459459
failwith "Bottom not expected when querying context state" (* Maybe this is reachable, failwith for now so we see when this happens *)
460-
else if Queries.ID.to_bool x = Some false then () (* Nothing to do, the c does definitely not satisfy the predicate of current_c *)
461-
else begin
460+
| `Lifted false ->
461+
() (* Nothing to do, the c does definitely not satisfy the predicate of current_c *)
462+
| `Lifted true
463+
| `Top ->
462464
(* Insert c into the list of weaker contexts of f *)
463-
FCMap.modify_def [] (f, current_c.context) (fun cs -> c::cs) fc_map;
464-
end
465+
FCMap.modify_def [] (f, current_c.context) (fun cs -> c::cs) fc_map
465466
) con_invs;
466467
| `Bot | `Top ->
467468
(* If the context invariant is None, we will not generate a precondition invariant. Nothing to do here. *)
@@ -747,15 +748,12 @@ struct
747748

748749
let result: VR.result = match InvariantParser.parse_cil inv_parser ~fundec ~loc inv_cabs with
749750
| Ok inv_exp ->
750-
let x = ask_local lvar (Queries.EvalInt inv_exp) in (* TODO: Queries.eval_bool? *)
751-
if Queries.ID.is_bot x || Queries.ID.is_bot_ikind x then (* dead code *)
752-
Option.get (VR.result_of_enum (VR.bot ()))
753-
else (
754-
match Queries.ID.to_bool x with
755-
| Some true -> Confirmed
756-
| Some false -> Refuted
757-
| None -> Unconfirmed
758-
)
751+
begin match Queries.eval_bool {f = (fun (type a) (q: a Queries.t) -> ask_local lvar q)} inv_exp with
752+
| `Bot -> Option.get (VR.result_of_enum (VR.bot ())) (* dead code *)
753+
| `Lifted true -> Confirmed
754+
| `Lifted false -> Refuted
755+
| `Top -> Unconfirmed
756+
end
759757
| Error e ->
760758
ParseError
761759
in
@@ -859,14 +857,11 @@ struct
859857

860858
match InvariantParser.parse_cil inv_parser ~fundec ~loc pre_cabs with
861859
| Ok pre_exp ->
862-
let x = ask_local pre_lvar (Queries.EvalInt pre_exp) in (* TODO: Queries.eval_bool? *)
863-
if Queries.ID.is_bot x || Queries.ID.is_bot_ikind x then (* dead code *)
864-
true
865-
else (
866-
match Queries.ID.to_bool x with
867-
| Some b -> b
868-
| None -> false
869-
)
860+
begin match Queries.eval_bool {f = (fun (type a) (q: a Queries.t) -> ask_local pre_lvar q)} pre_exp with
861+
| `Bot -> true (* dead code *)
862+
| `Lifted b -> b
863+
| `Top -> false
864+
end
870865
| Error e ->
871866
M.error ~category:Witness ~loc:msgLoc "CIL couldn't parse precondition: %s" pre;
872867
M.info ~category:Witness ~loc:msgLoc "precondition has undefined variables or side effects: %s" pre;

0 commit comments

Comments
 (0)