32
32
(* Returns Some true if we know for sure that it is true,
33
33
and Some false if we know for sure that it is false,
34
34
and None if we don't know anyhing. *)
35
- let eval_guard ask cc e ik =
35
+ let eval_guard ask d e ik =
36
+ let cc = d.data in
36
37
let open Queries in
37
38
let prop_list = T. prop_of_cil ask e true in
38
39
match split prop_list with
@@ -71,28 +72,30 @@ struct
71
72
let open Queries in
72
73
match ctx.local with
73
74
| `Bot -> Result. top q
74
- | `Lifted cc ->
75
+ | `Lifted d ->
75
76
match q with
76
77
| EvalInt e ->
77
78
let ik = Cilfacade. get_ikind_exp e in
78
- eval_guard (ask_of_man ctx) cc e ik
79
+ eval_guard (ask_of_man ctx) d e ik
79
80
| Queries. Invariant context ->
80
81
let scope = Node. find_fundec ctx.node in
81
- let t = D. remove_vars_not_in_scope scope cc in
82
- let conj = get_conjunction t in
82
+ let cc = D. remove_vars_not_in_scope scope d.data in
83
+ let conj = get_conjunction_from_data cc in
83
84
let ask = ask_of_man ctx in
84
85
conj_to_invariant ask conj
85
86
| _ ->
86
87
Result. top q
87
88
88
89
(* * Assign the right hand side rhs (that is already
89
90
converted to a C-2PO term) to the term `lterm`. *)
90
- let assign_term cc ask lterm rhs lval_t =
91
+ let assign_term d ask lterm rhs lval_t =
92
+ let cc = d.data in
91
93
(* ignore assignments to values that are not 64 bits *)
92
94
match T. get_element_size_in_bits lval_t, rhs with
93
95
(* Indefinite assignment *)
94
96
| lval_size , (None, _ ) ->
95
- D. remove_may_equal_terms ask lval_size lterm cc
97
+ let cc = D. remove_may_equal_terms ask lval_size lterm cc in
98
+ data_to_t cc
96
99
(* Definite assignment *)
97
100
| lval_size , (Some rterm , Some roffset ) ->
98
101
let dummy_var = MayBeEqual. dummy_var lval_t in
@@ -106,8 +109,8 @@ struct
106
109
meet_conjs_opt equal_dummy_rterm |>
107
110
D. remove_may_equal_terms ask lval_size lterm |>
108
111
meet_conjs_opt equal_dummy_lterm |>
109
- D. remove_terms_containing_aux_variable
110
-
112
+ D. remove_terms_containing_aux_variable |>
113
+ data_to_t
111
114
| _ -> (* this is impossible *)
112
115
C2PODomain. top ()
113
116
@@ -131,8 +134,8 @@ struct
131
134
match ctx.local with
132
135
| `Bot ->
133
136
`Bot
134
- | `Lifted cc ->
135
- let cc = assign_lval cc ask lval (T. of_cil ask expr) in
137
+ | `Lifted d ->
138
+ let cc = assign_lval d ask lval (T. of_cil ask expr) in
136
139
let cc = reset_normal_form cc in
137
140
let res = `Lifted cc in
138
141
if M. tracing then M. trace " c2po-assign" " assign: var: %a; expr: %a; result: %s.\n " d_lval lval d_plainexp expr (D. show res);
@@ -144,13 +147,13 @@ struct
144
147
let res =
145
148
match ctx.local with
146
149
| `Bot -> `Bot
147
- | `Lifted cc ->
150
+ | `Lifted d ->
148
151
if List. is_empty valid_props then
149
- `Lifted cc
152
+ `Lifted d
150
153
else
151
154
try
152
- let meet = meet_conjs_opt valid_props cc in
153
- let t = reset_normal_form meet in
155
+ let meet = meet_conjs_opt valid_props d.data in
156
+ let t = data_to_t meet in
154
157
`Lifted t
155
158
with Unsat ->
156
159
`Bot
@@ -167,8 +170,8 @@ struct
167
170
match T. of_cil ask expr with
168
171
| (Some term , Some offset ) ->
169
172
let ret_var_eq_term = [Equal (return_var, term, offset)] in
170
- let assign_by_meet = meet_conjs_opt ret_var_eq_term d in
171
- reset_normal_form assign_by_meet
173
+ let assign_by_meet = meet_conjs_opt ret_var_eq_term d.data in
174
+ data_to_t assign_by_meet
172
175
| _ -> d
173
176
174
177
let return ctx exp_opt f =
@@ -194,25 +197,27 @@ struct
194
197
let ask = ask_of_man ctx in
195
198
match ctx.local with
196
199
| `Bot -> `Bot
197
- | `Lifted cc ->
200
+ | `Lifted d ->
198
201
let t =
199
202
begin match lval_opt with
200
203
| None ->
201
- cc
204
+ d
202
205
| Some lval ->
203
206
(* forget information about var,
204
207
but ignore assignments to values that are not 64 bits *)
205
208
try
206
209
let size = T. get_element_size_in_bits (typeOfLval lval) in
207
210
let lterm = T. of_lval ask lval in
208
- let cc = D. remove_may_equal_terms ask size lterm cc in
209
- begin match desc.special exprs with
211
+ let cc = D. remove_may_equal_terms ask size lterm d.data in
212
+ let cc = begin match desc.special exprs with
210
213
| Malloc _
211
214
| Calloc _
212
215
| Alloca _ ->
213
216
add_block_diseqs cc lterm
214
217
| _ -> cc
215
218
end
219
+ in
220
+ data_to_t cc
216
221
with T. UnsupportedCilExpression _ ->
217
222
C2PODomain. top ()
218
223
end
@@ -224,7 +229,7 @@ struct
224
229
else
225
230
branch ctx exp true
226
231
| _ ->
227
- `Lifted (reset_normal_form t)
232
+ `Lifted t
228
233
229
234
(* * First all local variables of the function are duplicated,
230
235
then we remember the value of each local variable at the beginning of the function by using the analysis startState.
@@ -233,13 +238,14 @@ struct
233
238
(* add duplicated variables, and set them equal to the original variables *)
234
239
match ctx.local with
235
240
| `Bot -> [`Bot , `Bot ]
236
- | `Lifted cc ->
241
+ | `Lifted d ->
237
242
let ghost_equality v =
238
243
Equal (T. term_of_varinfo (DuplicVar v), T. term_of_varinfo (NormalVar v), Z. zero)
239
244
in
240
245
let ghost_equalities_for_params = List. map ghost_equality f.sformals in
241
246
let equalities_to_add = T. filter_valid_pointers ghost_equalities_for_params in
242
- let state_with_ghosts = meet_conjs_opt equalities_to_add cc in
247
+ let state_with_ghosts = meet_conjs_opt equalities_to_add d.data in
248
+ let state_with_ghosts = data_to_t state_with_ghosts in
243
249
if M. tracing then begin
244
250
let dummy_lval = Var (Var. dummy_varinfo (TVoid [] )), NoOffset in
245
251
let lval = BatOption. default dummy_lval var_opt in
@@ -250,7 +256,8 @@ struct
250
256
let reachable = f.sformals @ f.slocals @ reachable_from_args ctx args in
251
257
Var. from_varinfo reachable f.sformals
252
258
in
253
- let new_state = D. remove_terms_not_containing_variables reachable_variables state_with_ghosts in
259
+ let new_state = D. remove_terms_not_containing_variables reachable_variables state_with_ghosts.data in
260
+ let new_state = data_to_t new_state in
254
261
if M. tracing then M. trace " c2po-function" " enter2: result: %s\n " (C2PODomain. show new_state);
255
262
let new_state = reset_normal_form new_state in
256
263
[ctx.local, `Lifted new_state]
@@ -264,7 +271,7 @@ struct
264
271
let combine_env ctx lval_opt expr f args t_context_opt f_d (f_ask : Queries.ask ) =
265
272
match ctx.local with
266
273
| `Bot -> `Bot
267
- | `Lifted cc ->
274
+ | `Lifted d ->
268
275
let caller_ask = ask_of_man ctx in
269
276
(* assign function parameters to duplicated values *)
270
277
let arg_assigns = GobList. combine_short f.sformals args in
@@ -273,30 +280,32 @@ struct
273
280
let arg = T. of_cil f_ask arg in
274
281
assign_term st caller_ask ghost_var arg var.vtype
275
282
in
276
- let state_with_assignments = List. fold_left assign_term cc arg_assigns in
283
+ let state_with_assignments = List. fold_left assign_term d arg_assigns in
277
284
278
285
if M. tracing then M. trace " c2po-function" " combine_env0: state_with_assignments: %s\n " (C2PODomain. show state_with_assignments);
279
286
280
287
(* remove all variables that were tainted by the function*)
281
288
let tainted = f_ask.f (MayBeTainted ) in
282
289
if M. tracing then M. trace " c2po-tainted" " combine_env1: %a\n " MayBeEqual.AD. pretty tainted;
283
290
284
- let local = D. remove_tainted_terms caller_ask tainted state_with_assignments in
291
+ let local = D. remove_tainted_terms caller_ask tainted state_with_assignments.data in
292
+ let local = data_to_t local in
285
293
match D. meet (`Lifted local) f_d with
286
294
| `Bot -> `Bot
287
- | `Lifted cc ->
288
- let cc = reset_normal_form @@ remove_out_of_scope_vars cc f in
295
+ | `Lifted d ->
296
+ let cc = remove_out_of_scope_vars d.data f in
297
+ let d = data_to_t cc in
289
298
if M. tracing then begin
290
299
let dummy_lval = Var (Var. dummy_varinfo (TVoid [] )), NoOffset in
291
300
let lval = BatOption. default dummy_lval lval_opt in
292
- M. trace " c2po-function" " combine_env2: var_opt: %a; local_state: %s; f_state: %s; meeting everything: %s\n " d_lval lval (D. show ctx.local) (D. show f_d) (C2PODomain. show cc )
301
+ M. trace " c2po-function" " combine_env2: var_opt: %a; local_state: %s; f_state: %s; meeting everything: %s\n " d_lval lval (D. show ctx.local) (D. show f_d) (C2PODomain. show d )
293
302
end ;
294
- `Lifted cc
303
+ `Lifted d
295
304
296
305
let combine_assign ctx var_opt expr f args t_context_opt f_d (f_ask : Queries.ask ) =
297
306
match ctx.local with
298
307
| `Bot -> `Bot
299
- | `Lifted cc ->
308
+ | `Lifted d ->
300
309
let caller_ask = ask_of_man ctx in
301
310
(* assign function parameters to duplicated values *)
302
311
let arg_assigns = GobList. combine_short f.sformals args in
@@ -305,24 +314,24 @@ struct
305
314
let arg = T. of_cil f_ask arg in
306
315
assign_term st caller_ask ghost_var arg var.vtype
307
316
in
308
- let state_with_assignments = List. fold_left assign_term cc arg_assigns in
317
+ let state_with_assignments = List. fold_left assign_term d arg_assigns in
309
318
match D. meet (`Lifted state_with_assignments) f_d with
310
319
| `Bot -> `Bot
311
- | `Lifted cc ->
312
- let cc = match var_opt with
320
+ | `Lifted d ->
321
+ let d = match var_opt with
313
322
| None ->
314
- cc
323
+ d
315
324
| Some lval ->
316
325
let return_type = typeOfLval lval in
317
326
let return_var = MayBeEqual. return_var return_type in
318
327
let return_var = (Some return_var, Some Z. zero) in
319
- assign_lval cc f_ask lval return_var
328
+ assign_lval d f_ask lval return_var
320
329
in
321
- if M. tracing then M. trace " c2po-function" " combine_assign1: assigning return value: %s\n " (C2PODomain. show cc );
322
- let cc = remove_out_of_scope_vars cc f in
323
- let cc = reset_normal_form cc in
324
- if M. tracing then M. trace " c2po-function" " combine_assign2: result: %s\n " (C2PODomain. show cc );
325
- `Lifted cc
330
+ if M. tracing then M. trace " c2po-function" " combine_assign1: assigning return value: %s\n " (C2PODomain. show d );
331
+ let d = remove_out_of_scope_vars d.data f in
332
+ let d = data_to_t d in
333
+ if M. tracing then M. trace " c2po-function" " combine_assign2: result: %s\n " (C2PODomain. show d );
334
+ `Lifted d
326
335
327
336
let startstate v =
328
337
D. top ()
0 commit comments