Skip to content
Snippets Groups Projects
Commit 699c1f84 authored by Allan Blanchard's avatar Allan Blanchard
Browse files

[wp] Do not ignore main declaration

parent cb6150a1
No related branches found
No related tags found
No related merge requests found
...@@ -129,7 +129,7 @@ struct ...@@ -129,7 +129,7 @@ struct
type env = { type env = {
mode: mode; mode: mode;
props: props; props: props;
cfg: Cfg.automaton; cfg: Cfg.automaton option;
we: W.t_env; we: W.t_env;
wp: W.t_prop option Vhash.t; (* None is used for non-dag detection *) wp: W.t_prop option Vhash.t; (* None is used for non-dag detection *)
mutable wk: W.t_prop; (* end point *) mutable wk: W.t_prop; (* end point *)
...@@ -179,7 +179,7 @@ struct ...@@ -179,7 +179,7 @@ struct
exception NonNaturalLoop exception NonNaturalLoop
let succ env a = G.succ_e env.cfg.graph a let succ env a = G.succ_e (Option.get env.cfg).graph a
let rec wp (env:env) (a:vertex) : W.t_prop = let rec wp (env:env) (a:vertex) : W.t_prop =
match Vhash.find env.wp a with match Vhash.find env.wp a with
...@@ -356,11 +356,12 @@ struct ...@@ -356,11 +356,12 @@ struct
prove_assigns env b.bhv_exit_assigns w prove_assigns env b.bhv_exit_assigns w
let do_funbehavior env ~formals (b : CfgAnnot.behavior) w = let do_funbehavior env ~formals (b : CfgAnnot.behavior) w =
let cfg = Option.get env.cfg in
let wpost = do_post env ~formals b w in let wpost = do_post env ~formals b w in
let wexit = do_exit env ~formals b w in let wexit = do_exit env ~formals b w in
Vhash.add env.wp env.cfg.return_point (Some wpost) ; Vhash.add env.wp cfg.return_point (Some wpost) ;
env.wk <- wexit ; env.wk <- wexit ;
wp env env.cfg.entry_point wp env cfg.entry_point
(* Putting everything together *) (* Putting everything together *)
let compute ~mode ~props = let compute ~mode ~props =
...@@ -381,7 +382,9 @@ struct ...@@ -381,7 +382,9 @@ struct
do_global_init env @@ do_global_init env @@
do_preconditions env ~formals bhv @@ do_preconditions env ~formals bhv @@
do_complete_disjoint env @@ do_complete_disjoint env @@
do_funbehavior env ~formals bhv @@ (if Kernel_function.has_definition kf
then do_funbehavior env ~formals bhv
else Extlib.id) @@
W.empty W.empty
end end
......
...@@ -162,12 +162,11 @@ let strategy_main model task ?(fct=Fct_all) ?(bhv=[]) ?(prop=[]) () = ...@@ -162,12 +162,11 @@ let strategy_main model task ?(fct=Fct_all) ?(bhv=[]) ?(prop=[]) () =
LogicUsage.iter_lemmas (lemma task ~prop) ; LogicUsage.iter_lemmas (lemma task ~prop) ;
Wp_parameters.iter_fct Wp_parameters.iter_fct
(fun kf -> (fun kf ->
if Kernel_function.has_definition kf then let infos = get_kf_infos model kf ~bhv ~prop () in
let infos = get_kf_infos model kf ~bhv ~prop () in if CfgInfos.annots infos then
if CfgInfos.annots infos then if bhv=[]
if bhv=[] then apply model task ~infos ~kf ()
then apply model task ~infos ~kf () else apply model task ~infos ~kf ~bhvs:(select kf bhv) ()
else apply model task ~infos ~kf ~bhvs:(select kf bhv) ()
) fct ; ) fct ;
task.props <- (if prop=[] then `All else `Names prop); task.props <- (if prop=[] then `All else `Names prop);
end end
......
...@@ -30,7 +30,7 @@ module Shash = Cil_datatype.Stmt.Hashtbl ...@@ -30,7 +30,7 @@ module Shash = Cil_datatype.Stmt.Hashtbl
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
type t = { type t = {
cfg : Cfg.automaton; cfg : Cfg.automaton option;
mutable annots : bool; (* has goals to prove *) mutable annots : bool; (* has goals to prove *)
mutable doomed : WpPropId.prop_id Bag.t; mutable doomed : WpPropId.prop_id Bag.t;
mutable calls : Kernel_function.Set.t; mutable calls : Kernel_function.Set.t;
...@@ -60,7 +60,7 @@ let fixpoint h d f = ...@@ -60,7 +60,7 @@ let fixpoint h d f =
in phi in phi
let unreachable infos = let unreachable infos =
let pred = Cfg.G.pred infos.cfg.graph in let pred = Cfg.G.pred (Option.get infos.cfg).graph in
fixpoint infos.unreachable true fixpoint infos.unreachable true
begin fun phi v -> List.for_all phi (pred v) end begin fun phi v -> List.for_all phi (pred v) end
...@@ -120,6 +120,9 @@ let selected_bhv ~bhv ~prop (b : Cil_types.funbehavior) = ...@@ -120,6 +120,9 @@ let selected_bhv ~bhv ~prop (b : Cil_types.funbehavior) =
(List.exists (selected_postcond ~prop) b.b_post_cond) (List.exists (selected_postcond ~prop) b.b_post_cond)
end end
let selected_main_bhv ~bhv ~prop (b : Cil_types.funbehavior) =
(bhv = [] || List.mem b.b_name bhv) && (selected_requires ~prop) b
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
(* --- Calls --- *) (* --- Calls --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
...@@ -194,7 +197,10 @@ let loop_contract_pids kf stmt = ...@@ -194,7 +197,10 @@ let loop_contract_pids kf stmt =
| _ -> [] | _ -> []
let compile Key.{ kf ; bhv ; prop } = let compile Key.{ kf ; bhv ; prop } =
let cfg = Cfg.get_automaton kf in let cfg =
if Kernel_function.has_definition kf then Some (Cfg.get_automaton kf)
else None
in
let infos = { let infos = {
cfg ; cfg ;
annots = false ; annots = false ;
...@@ -202,36 +208,41 @@ let compile Key.{ kf ; bhv ; prop } = ...@@ -202,36 +208,41 @@ let compile Key.{ kf ; bhv ; prop } =
calls = Fset.empty ; calls = Fset.empty ;
unreachable = Vhash.create 32 ; unreachable = Vhash.create 32 ;
} in } in
(* Root Reachability *) let behaviors = Annotations.behaviors kf in
let v0 = cfg.entry_point in if WpStrategy.is_main_init kf then
Vhash.add infos.unreachable v0 false ; infos.annots <- List.exists (selected_main_bhv ~bhv ~prop) behaviors ;
(* Spec Iteration *)
if selected_disjoint_complete kf ~bhv ~prop || if Kernel_function.has_definition kf then begin
List.exists let cfg = Option.get cfg in
(selected_bhv ~bhv ~prop) (* Root Reachability *)
(Annotations.behaviors kf) let v0 = cfg.entry_point in
then infos.annots <- true ; Vhash.add infos.unreachable v0 false ;
(* Stmt Iteration *) (* Spec Iteration *)
Shash.iter if selected_disjoint_complete kf ~bhv ~prop ||
(fun stmt (src,_) -> (List.exists (selected_bhv ~bhv ~prop) behaviors)
let fs = collect_calls ~bhv stmt in then infos.annots <- true ;
let dead = unreachable infos src in (* Stmt Iteration *)
let ca = CfgAnnot.get_code_assertions kf stmt in Shash.iter
let ca_pids = List.map fst ca.code_verified in (fun stmt (src,_) ->
let loop_pids = loop_contract_pids kf stmt in let fs = collect_calls ~bhv stmt in
if dead then begin let dead = unreachable infos src in
infos.doomed <- Bag.concat infos.doomed (Bag.list ca_pids) ; let ca = CfgAnnot.get_code_assertions kf stmt in
infos.doomed <- Bag.concat infos.doomed (Bag.list loop_pids) ; let ca_pids = List.map fst ca.code_verified in
end else let loop_pids = loop_contract_pids kf stmt in
begin if dead then begin
if not infos.annots && infos.doomed <- Bag.concat infos.doomed (Bag.list ca_pids) ;
( List.exists (selected ~bhv ~prop) ca_pids || infos.doomed <- Bag.concat infos.doomed (Bag.list loop_pids) ;
List.exists (selected ~bhv ~prop) loop_pids || end else
Fset.exists (selected_call ~bhv ~prop) fs ) begin
then infos.annots <- true ; if not infos.annots &&
infos.calls <- Fset.union fs infos.calls ; ( List.exists (selected ~bhv ~prop) ca_pids ||
end List.exists (selected ~bhv ~prop) loop_pids ||
) cfg.stmt_table ; Fset.exists (selected_call ~bhv ~prop) fs )
then infos.annots <- true ;
infos.calls <- Fset.union fs infos.calls ;
end
) cfg.stmt_table ;
end ;
(* Collected Infos *) (* Collected Infos *)
infos infos
......
...@@ -30,7 +30,7 @@ module Cfg = Interpreted_automata ...@@ -30,7 +30,7 @@ module Cfg = Interpreted_automata
val get : Kernel_function.t -> ?bhv:string list -> ?prop:string list -> val get : Kernel_function.t -> ?bhv:string list -> ?prop:string list ->
unit -> t unit -> t
val cfg : t -> Cfg.automaton val cfg : t -> Cfg.automaton option
val annots : t -> bool val annots : t -> bool
val doomed : t -> WpPropId.prop_id Bag.t val doomed : t -> WpPropId.prop_id Bag.t
val calls : t -> Kernel_function.Set.t val calls : t -> Kernel_function.Set.t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment