Skip to content
Snippets Groups Projects
Commit fae4619a authored by Patrick Baudin's avatar Patrick Baudin
Browse files

[Wp] expose CIL invariants about initializer

parent e5d1c85a
No related branches found
No related tags found
No related merge requests found
...@@ -497,20 +497,20 @@ struct ...@@ -497,20 +497,20 @@ struct
let delayed = let delayed =
match len with (* number of required elements *) match len with (* number of required elements *)
| Some {enode = (Const CInt64 (size,_,_))} -> | Some {enode = (Const CInt64 (size,_,_))} ->
Some (size, None) (size, None)
| _ -> None | _ -> (* CIL invariant broken. *)
WpLog.fatal "CIL invariant broken: unknown initialized array size"
in in
let make_quant acc = function let make_quant acc = function
(* adds delayed initializations from info about (* adds delayed initializations from info about
the last consecutive indices having the last consecutive indices having
the same value, but that have not yet initialized. *) the same value, but that have not yet initialized. *)
| None -> acc (* nothing was delayed *) | (_,None) -> acc (* nothing was delayed *)
| Some (_,None) -> acc (* nothing was delayed *) | (il,Some (i0,_,exp)) when Integer.lt il i0 ->
| Some (il,Some (i0,_,exp)) when Integer.lt il i0 ->
(* Added pred: \forall i \in [il .. i0] ; t[i]==exp *) (* Added pred: \forall i \in [il .. i0] ; t[i]==exp *)
let i2 = Integer.succ i0 in let i2 = Integer.succ i0 in
init_range ~sigma lv ty il i2 (Some exp) :: acc init_range ~sigma lv ty il i2 (Some exp) :: acc
| Some (_il,Some (_i0,off,exp)) -> | (_il,Some (_i0,off,exp)) ->
(* case [_il=_i0], so uses [off] corresponding to [_i0] (* case [_il=_i0], so uses [off] corresponding to [_i0]
Added pred: t[i]==exp*) Added pred: t[i]==exp*)
let lv = Cil.addOffsetLval off lv in let lv = Cil.addOffsetLval off lv in
...@@ -518,12 +518,11 @@ struct ...@@ -518,12 +518,11 @@ struct
in in
let add_missing_indices acc i0 = function let add_missing_indices acc i0 = function
(* adds eventual default value for missing indices. *) (* adds eventual default value for missing indices. *)
| Some (i1, _) -> | (i1, _) ->
if Integer.ge i0 i1 then (* no hole *) acc if Integer.ge i0 i1 then (* no hole *) acc
else (* defaults values else (* defaults values
Added pred: \forall i \in [i0 .. i1[ ; t[i]==default *) Added pred: \forall i \in [i0 .. i1[ ; t[i]==default *)
init_range ~sigma lv ty i0 i1 None :: acc init_range ~sigma lv ty i0 i1 None :: acc
| _ -> (* last bound is unknown. *) acc
in in
let acc, delayed = let acc, delayed =
List.fold_left List.fold_left
...@@ -532,35 +531,36 @@ struct ...@@ -532,35 +531,36 @@ struct
let idx,acc = match off with let idx,acc = match off with
| Index({enode=Const CInt64 (idx,_,_)}, _) -> | Index({enode=Const CInt64 (idx,_,_)}, _) ->
(match delayed with (match delayed with
| Some (iprev, _) when Integer.lt iprev idx -> | (iprev, _) when Integer.lt iprev idx ->
(* otherwice, an algo with a 2sd pass is (* CIL invariant broken.
required for introducing default values *) without that invariant, an algo with a 2sd pass
WpLog.fatal "Unordered initializer"; is required for introducing default values *)
WpLog.fatal "CIL invariant broken: unordered initializer";
| _ -> ()) ; | _ -> ()) ;
Some (idx,None), idx,
(* adds default values for missing indices *) (* adds default values for missing indices *)
add_missing_indices acc (Integer.succ idx) delayed add_missing_indices acc (Integer.succ idx) delayed
| _ -> None,acc | _ -> (* CIL invariant broken. *)
WpLog.fatal "CIL invariant broken: unknown initialized index"
in in
match idx, off, init with (* only simple init can be delayed *) match off, init with (* only simple init can be delayed *)
| Some (idx,_), Index(_, NoOffset), SingleInit init -> begin | Index(_, NoOffset), SingleInit init -> begin
match delayed with match delayed with
| None -> acc,Some (idx,Some(idx,off,init)) | (i_prev,(Some (_,_,init_delayed) as delayed_info))
| Some (i_prev,(Some (_,_,init_delayed) as delayed_info))
when Wp_parameters.InitWithForall.get () when Wp_parameters.InitWithForall.get ()
&& Integer.equal (Integer.pred i_prev) idx && Integer.equal (Integer.pred i_prev) idx
&& ExpStructEq.equal init_delayed init -> && ExpStructEq.equal init_delayed init ->
acc,Some (idx,delayed_info) acc, (idx,delayed_info)
| _ -> (* flush the delayed init, and store the new one *) | _ -> (* flush the delayed init, and store the new one *)
let acc = make_quant acc delayed in let acc = make_quant acc delayed in
acc, Some (idx, Some (idx,off,init)) acc, (idx, Some (idx,off,init))
end end
| _, Index(_, _),_ -> | Index(_, _),_ ->
(* flush the delayed init, and adds the current one *) (* flush the delayed init, and adds the current one *)
let acc = make_quant acc delayed in let acc = make_quant acc delayed in
let lv = Cil.addOffsetLval off lv in let lv = Cil.addOffsetLval off lv in
(init_variable ~sigma lv init acc), idx (init_variable ~sigma lv init acc), (idx, None)
| _ -> WpLog.fatal "Kernel invariant broken into an initializer" | _ -> WpLog.fatal "CIL invariant broken: not an index"
) )
(acc,delayed) (acc,delayed)
(List.rev initl) (List.rev initl)
......
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