Skip to content

Commit 7c2322a

Browse files
committed
Extract query_invariant_transition in relation analysis
1 parent 49c6ee6 commit 7c2322a

File tree

1 file changed

+54
-51
lines changed

1 file changed

+54
-51
lines changed

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -265,61 +265,64 @@ struct
265265
if M.tracing then M.traceu "relation" "-> %a" D.pretty r;
266266
r
267267

268-
let branch man e b =
268+
let query_invariant_transition man =
269269
let st = man.local in
270270
let ask = Analyses.ask_of_man man in
271-
let () =
272-
let r1 = RD.keep_filter st.rel (fun var ->
273-
match RV.find_metadata var with
274-
| Some (Local _) -> true
275-
| _ -> false
271+
let r1 = RD.keep_filter st.rel (fun var ->
272+
match RV.find_metadata var with
273+
| Some (Local _) -> true
274+
| _ -> false
275+
)
276+
in
277+
Logs.debug "r1: %a" RD.pretty r1;
278+
let r1vars = RD.vars r1 in
279+
let r1vars' = List.map (fun var ->
280+
match RV.find_metadata var with
281+
| Some (Local x) -> RV.arg x
282+
| _ -> assert false
283+
) r1vars
284+
in
285+
let r2 = RD.add_vars r1 r1vars' in
286+
let r2' = RD.assign_var_parallel' r2 r1vars' r1vars in
287+
let r3 = RD.keep_vars r2' r1vars' in
288+
Logs.debug "r3: %a" RD.pretty r3;
289+
(* let r3' = RD.assr3 in *)
290+
(* Logs.debug "r3': %a" RD.pretty r3'; *)
291+
let r4 = RD.unify r1 r3 in
292+
let r5 =
293+
List.fold_left (fun acc var ->
294+
match RV.to_cil_varinfo var with
295+
| Some vi when TerminationPreprocessing.VarToStmt.mem vi !LoopTermination.loop_counters ->
296+
let open Apron in
297+
let env = RD.env acc in
298+
(* let tcons1 = Tcons1.make Texpr1.(binop Sub (var env (RV.local vi)) (var env (RV.arg vi)) Int Zero) Lincons1.SUP in (* with AnyPrev *) *)
299+
let tcons1 = Tcons1.make Texpr1.(binop Sub (binop Sub (var env (RV.local vi)) (var env (RV.arg vi)) Int Zero) (cst env (Coeff.s_of_int 1)) Int Zero) Lincons1.EQ in (* with LastPrev *)
300+
let acc' = RD.meet_tcons ask acc tcons1 MyCFG.unknown_exp (lazy false) in
301+
RD.remove_vars acc' [RV.local vi; RV.arg vi]
302+
| _ ->
303+
acc
304+
) r4 r1vars
305+
in
306+
Logs.debug "r5: %a" RD.pretty r5;
307+
let scope = Node.find_fundec man.node in
308+
let e_inv = Fun.id in (* TODO: handle globals? *)
309+
let inv =
310+
RD.invariant r5
311+
|> List.to_seq
312+
|> Seq.filter_map (fun (lincons1: Apron.Lincons1.t) ->
313+
RD.cil_exp_of_lincons1 lincons1
314+
|> Option.map e_inv
315+
|> Option.filter (fun exp -> not (InvariantCil.exp_contains_tmp exp) && InvariantCil.exp_is_in_scope scope exp)
276316
)
277-
in
278-
Logs.debug "r1: %a" RD.pretty r1;
279-
let r1vars = RD.vars r1 in
280-
let r1vars' = List.map (fun var ->
281-
match RV.find_metadata var with
282-
| Some (Local x) -> RV.arg x
283-
| _ -> assert false
284-
) r1vars
285-
in
286-
let r2 = RD.add_vars r1 r1vars' in
287-
let r2' = RD.assign_var_parallel' r2 r1vars' r1vars in
288-
let r3 = RD.keep_vars r2' r1vars' in
289-
Logs.debug "r3: %a" RD.pretty r3;
290-
(* let r3' = RD.assr3 in *)
291-
(* Logs.debug "r3': %a" RD.pretty r3'; *)
292-
let r4 = RD.unify r1 r3 in
293-
let r5 =
294-
List.fold_left (fun acc var ->
295-
match RV.to_cil_varinfo var with
296-
| Some vi when TerminationPreprocessing.VarToStmt.mem vi !LoopTermination.loop_counters ->
297-
let open Apron in
298-
let env = RD.env acc in
299-
(* let tcons1 = Tcons1.make Texpr1.(binop Sub (var env (RV.local vi)) (var env (RV.arg vi)) Int Zero) Lincons1.SUP in (* with AnyPrev *) *)
300-
let tcons1 = Tcons1.make Texpr1.(binop Sub (binop Sub (var env (RV.local vi)) (var env (RV.arg vi)) Int Zero) (cst env (Coeff.s_of_int 1)) Int Zero) Lincons1.EQ in (* with LastPrev *)
301-
let acc' = RD.meet_tcons ask acc tcons1 MyCFG.unknown_exp (lazy false) in
302-
RD.remove_vars acc' [RV.local vi; RV.arg vi]
303-
| _ ->
304-
acc
305-
) r4 r1vars
306-
in
307-
Logs.debug "r5: %a" RD.pretty r5;
308-
let scope = Node.find_fundec man.node in
309-
let e_inv = Fun.id in (* TODO: handle globals? *)
310-
let inv =
311-
RD.invariant r5
312-
|> List.to_seq
313-
|> Seq.filter_map (fun (lincons1: Apron.Lincons1.t) ->
314-
RD.cil_exp_of_lincons1 lincons1
315-
|> Option.map e_inv
316-
|> Option.filter (fun exp -> not (InvariantCil.exp_contains_tmp exp) && InvariantCil.exp_is_in_scope scope exp)
317-
)
318-
|> Seq.fold_left (fun acc x -> Invariant.(acc && of_exp x)) Invariant.none
319-
in
320-
Logs.debug "inv: %a" Invariant.pretty inv;
321-
()
317+
|> Seq.fold_left (fun acc x -> Invariant.(acc && of_exp x)) Invariant.none
322318
in
319+
Logs.debug "inv: %a" Invariant.pretty inv;
320+
()
321+
322+
let branch man e b =
323+
let st = man.local in
324+
let ask = Analyses.ask_of_man man in
325+
query_invariant_transition man;
323326
let res = assign_from_globals_wrapper ask man.global st e (fun rel' e' ->
324327
(* not an assign, but must remove g#in-s still *)
325328
RD.assert_inv ask rel' e' (not b) (no_overflow ask e)

0 commit comments

Comments
 (0)