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

[wp] Partial refactoring of main compute procedure

parent c6d61b96
No related branches found
No related tags found
No related merge requests found
...@@ -134,12 +134,7 @@ struct ...@@ -134,12 +134,7 @@ struct
cfg: Cfg.automaton ; cfg: Cfg.automaton ;
} }
let rec has_reachable_call cfg v = let rec reachable_call_by_cfg env a =
let env = { table = Vhash.create 32 ; cfg } in
try reachable_call_by_cfg env v ; false
with Found_call -> true
and reachable_call_by_cfg env a =
try Vhash.find env.table a try Vhash.find env.table a
with Not_found -> with Not_found ->
Vhash.add env.table a () ; Vhash.add env.table a () ;
...@@ -151,6 +146,11 @@ struct ...@@ -151,6 +146,11 @@ struct
| Instr ((Local_init(_,ConsInit _, _)| Call _), _) -> raise Found_call | Instr ((Local_init(_,ConsInit _, _)| Call _), _) -> raise Found_call
| _ -> () | _ -> ()
let has_reachable_call cfg v =
let env = { table = Vhash.create 32 ; cfg } in
try reachable_call_by_cfg env v ; false
with Found_call -> true
end end
(* --- Traversal Environment --- *) (* --- Traversal Environment --- *)
...@@ -185,7 +185,7 @@ struct ...@@ -185,7 +185,7 @@ struct
match a with match a with
| NoAssignsInfo -> assert false | NoAssignsInfo -> assert false
| AssignsAny ad -> | AssignsAny ad ->
Wp_parameters.warning ~current:true ~once:true WpLog.warning ~current:true ~once:true
"Missing assigns clause (assigns 'everything' instead)" ; "Missing assigns clause (assigns 'everything' instead)" ;
W.use_assigns env.we None ad w W.use_assigns env.we None ad w
| AssignsLocations(ap,ad) -> W.use_assigns env.we (Some ap) ad w | AssignsLocations(ap,ad) -> W.use_assigns env.we (Some ap) ad w
...@@ -367,40 +367,56 @@ struct ...@@ -367,40 +367,56 @@ struct
if not @@ WpStrategy.is_main_init kf then Extlib.id if not @@ WpStrategy.is_main_init kf then Extlib.id
else List.fold_right (prove_property env) ps else List.fold_right (prove_property env) ps
in in
let do_preconditions env w =
List.fold_right (use_property env) req @@
List.fold_right (use_property env) bhv.bhv_assumes @@
prove_if_main env bhv.bhv_requires @@
List.fold_right (use_property env) bhv.bhv_requires @@
List.fold_right (use_property env) (behaviors kf) w
in
let do_complete_disjoint env w =
List.fold_right (prove_property env) (complete mode kf) @@
List.fold_right (prove_property env) (disjoint mode kf) w
in
let do_function_body env w =
Vhash.add env.wp env.cfg.return_point (Some w) ;
wp env env.cfg.entry_point
in
let do_post_exit env w =
let w_exit =
W.scope env.we xs SC_Frame_out @@
W.label env.we None Clabels.at_exit @@
List.fold_right (prove_property env) bhv.bhv_exits @@
if not has_exit then w else prove_assigns env bhv.bhv_exit_assigns w
in
let w_post =
W.scope env.we xs SC_Frame_out @@
W.label env.we None Clabels.post @@
List.fold_right (prove_property env) bhv.bhv_ensures @@
prove_assigns env bhv.bhv_post_assigns w
in
env.wk <- w_exit ;
w_post
in
env.we , env.we ,
(* global init *) (* global init *)
W.close env.we @@ W.close env.we @@
I.process_global_init env.we kf @@ I.process_global_init env.we kf @@
W.scope env.we [] SC_Global @@ W.scope env.we [] SC_Global @@
(* pre-state *) (* pre-state *)
W.label env.we None Clabels.pre @@ W.label env.we None Clabels.pre @@
List.fold_right (use_property env) req @@
List.fold_right (use_property env) bhv.bhv_assumes @@
prove_if_main env bhv.bhv_requires @@
List.fold_right (use_property env) bhv.bhv_requires @@
List.fold_right (use_property env) (behaviors kf) @@
List.fold_right (prove_property env) (complete mode kf) @@
List.fold_right (prove_property env) (disjoint mode kf) @@
(* frame-in *) (* frame-in *)
W.scope env.we xs SC_Frame_in @@ W.scope env.we xs SC_Frame_in @@
(* function body *)
begin fun w ->
Vhash.add env.wp env.cfg.return_point (Some w) ;
wp env env.cfg.entry_point
end @@
(* frame-out *)
W.scope env.we xs SC_Frame_out @@
(* Post-conds*)
W.label env.we None Clabels.post @@
begin fun w ->
env.wk <-
List.fold_right (prove_property env) bhv.bhv_exits @@
if not has_exit then w else prove_assigns env bhv.bhv_exit_assigns w ;
List.fold_right (prove_property env) bhv.bhv_ensures @@ do_preconditions env @@
prove_assigns env bhv.bhv_post_assigns w do_complete_disjoint env @@
end @@ do_function_body env @@
(* NOTE: do_post_exit performs frame-out on both post and exit *)
(* Post-conds*)
do_post_exit env @@
(* wp-end *) (* wp-end *)
W.empty W.empty
......
void bar(void);
/*@
ensures \valid(&f);
exits \valid(&f);
*/
void foo(int f){
bar();
}
# frama-c -wp [...]
[kernel] Parsing tests/wp/exit_post_scope.i (no preprocessing)
[wp] Running WP plugin...
[kernel:annot:missing-spec] tests/wp/exit_post_scope.i:7: Warning:
Neither code nor specification for function bar, generating default assigns from the prototype
[wp] Warning: Missing RTE guards
------------------------------------------------------------
Function foo
------------------------------------------------------------
Goal Post-condition (file tests/wp/exit_post_scope.i, line 4) in 'foo':
Prove: false.
------------------------------------------------------------
Goal Exit-condition (file tests/wp/exit_post_scope.i, line 5) in 'foo':
Prove: false.
------------------------------------------------------------
# frama-c -wp [...]
[kernel] Parsing tests/wp/exit_post_scope.i (no preprocessing)
[wp] Running WP plugin...
[kernel:annot:missing-spec] tests/wp/exit_post_scope.i:7: Warning:
Neither code nor specification for function bar, generating default assigns from the prototype
[wp] Warning: Missing RTE guards
[wp] 2 goals scheduled
[wp] [Alt-Ergo] Goal typed_foo_ensures : Unsuccess
[wp] [Alt-Ergo] Goal typed_foo_exits : Unsuccess
[wp] Proved goals: 0 / 2
Alt-Ergo: 0 (unsuccess: 2)
------------------------------------------------------------
Functions WP Alt-Ergo Total Success
foo - - 2 0.0%
------------------------------------------------------------
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