@@ -7,21 +7,12 @@ open Analyses
77module Cil = GoblintCil. Cil
88
99module NH = CfgTools. NH
10- module FH = Hashtbl. Make (CilType. Fundec )
11- module EH = Hashtbl. Make (CilType. Exp )
1210
1311module Spec =
1412struct
15- (* TODO: Should be context-sensitive? Some spurious widening in knot_comb fails self-validation after self-unassume. *)
16- include Analyses. IdentityUnitContextsSpec
13+ include UnitAnalysis. Spec
1714 let name () = " unassume"
1815
19- module D = SetDomain. Make (CilType. Exp )
20-
21- let startstate _ = D. empty ()
22- let morphstate _ _ = D. empty ()
23- let exitstate _ = D. empty ()
24-
2516 module Locator = WitnessUtil. Locator (Node )
2617
2718 let location_locator: Locator. t = Locator. create () (* empty default, so don't have to use option everywhere *)
3425
3526 let invs: inv NH. t = NH. create 100
3627
37- let fun_pres: Cil. exp FH. t = FH. create 100
38- let pre_invs: inv EH. t NH. t = NH. create 100
39-
4028 let init _ =
4129 Locator. clear location_locator;
4230 Locator. clear loop_locator;
8371 let inv_parser = InvariantParser. create ! Cilfacade. current_file in
8472
8573 NH. clear invs;
86- FH. clear fun_pres;
87- NH. clear pre_invs;
8874
8975 let unassume_entry (entry : YamlWitnessType.Entry.t ) =
9076 let uuid = entry.metadata.uuid in
@@ -112,81 +98,6 @@ struct
11298 M. info ~category: Witness ~loc: msgLoc " invariant has invalid syntax: %s" inv
11399 in
114100
115- let unassume_location_invariant (location_invariant : YamlWitnessType.LocationInvariant.t ) =
116- let loc = YamlWitness. loc_of_location location_invariant.location in
117- let inv = location_invariant.location_invariant.string in
118- let msgLoc: M.Location. t = CilLocation loc in
119-
120- match Locator. find_opt location_locator loc with
121- | Some nodes ->
122- unassume_nodes_invariant ~loc ~nodes inv
123- | None ->
124- M. warn ~category: Witness ~loc: msgLoc " couldn't locate invariant: %s" inv
125- in
126-
127- let unassume_loop_invariant (loop_invariant : YamlWitnessType.LoopInvariant.t ) =
128- let loc = YamlWitness. loc_of_location loop_invariant.location in
129- let inv = loop_invariant.loop_invariant.string in
130- let msgLoc: M.Location. t = CilLocation loc in
131-
132- match Locator. find_opt loop_locator loc with
133- | Some nodes ->
134- unassume_nodes_invariant ~loc ~nodes inv
135- | None ->
136- M. warn ~category: Witness ~loc: msgLoc " couldn't locate invariant: %s" inv
137- in
138-
139- let unassume_precondition_nodes_invariant ~loc ~nodes pre inv =
140- let msgLoc: M.Location. t = CilLocation loc in
141- match InvariantParser. parse_cabs pre, InvariantParser. parse_cabs inv with
142- | Ok pre_cabs , Ok inv_cabs ->
143-
144- Locator.ES. iter (fun n ->
145- let fundec = Node. find_fundec n in
146-
147- match InvariantParser. parse_cil inv_parser ~check: false ~fundec ~loc pre_cabs with
148- | Ok pre_exp ->
149- M. debug ~category: Witness ~loc: msgLoc " located precondition to %a: %a" CilType.Fundec. pretty fundec Cil. d_exp pre_exp;
150- FH. add fun_pres fundec pre_exp;
151-
152- begin match InvariantParser. parse_cil inv_parser ~check: false ~fundec ~loc inv_cabs with
153- | Ok inv_exp ->
154- M. debug ~category: Witness ~loc: msgLoc " located invariant to %a: %a" Node. pretty n Cil. d_exp inv_exp;
155- if not (NH. mem pre_invs n) then
156- NH. replace pre_invs n (EH. create 10 );
157- EH. add (NH. find pre_invs n) pre_exp {exp = inv_exp; token = (uuid, None )}
158- | Error e ->
159- M. error ~category: Witness ~loc: msgLoc " CIL couldn't parse invariant: %s" inv;
160- M. info ~category: Witness ~loc: msgLoc " invariant has undefined variables or side effects: %s" inv
161- end
162-
163- | Error e ->
164- M. error ~category: Witness ~loc: msgLoc " CIL couldn't parse precondition: %s" pre;
165- M. info ~category: Witness ~loc: msgLoc " precondition has undefined variables or side effects: %s" pre
166- ) nodes;
167-
168- | Error e , _ ->
169- M. error ~category: Witness ~loc: msgLoc " Frontc couldn't parse precondition: %s" pre;
170- M. info ~category: Witness ~loc: msgLoc " precondition has invalid syntax: %s" pre
171-
172- | _ , Error e ->
173- M. error ~category: Witness ~loc: msgLoc " Frontc couldn't parse invariant: %s" inv;
174- M. info ~category: Witness ~loc: msgLoc " invariant has invalid syntax: %s" inv
175- in
176-
177- let unassume_precondition_loop_invariant (precondition_loop_invariant : YamlWitnessType.PreconditionLoopInvariant.t ) =
178- let loc = YamlWitness. loc_of_location precondition_loop_invariant.location in
179- let pre = precondition_loop_invariant.precondition.string in
180- let inv = precondition_loop_invariant.loop_invariant.string in
181- let msgLoc: M.Location. t = CilLocation loc in
182-
183- match Locator. find_opt loop_locator loc with
184- | Some nodes ->
185- unassume_precondition_nodes_invariant ~loc ~nodes pre inv
186- | None ->
187- M. warn ~category: Witness ~loc: msgLoc " couldn't locate invariant: %s" inv
188- in
189-
190101 let unassume_invariant_set (invariant_set : YamlWitnessType.InvariantSet.t ) =
191102
192103 let unassume_location_invariant ~i (location_invariant : YamlWitnessType.InvariantSet.LocationInvariant.t ) =
@@ -239,15 +150,9 @@ struct
239150 in
240151
241152 match YamlWitness. entry_type_enabled target_type, entry.entry_type with
242- | true , LocationInvariant x ->
243- unassume_location_invariant x
244- | true , LoopInvariant x ->
245- unassume_loop_invariant x
246- | true , PreconditionLoopInvariant x ->
247- unassume_precondition_loop_invariant x
248153 | true , InvariantSet x ->
249154 unassume_invariant_set x
250- | false , ( LocationInvariant _ | LoopInvariant _ | PreconditionLoopInvariant _ | InvariantSet _ ) ->
155+ | false , InvariantSet _ ->
251156 M. info_noloc ~category: Witness " disabled entry of type %s" target_type
252157 | _ ->
253158 M. warn_noloc ~category: Witness " cannot unassume entry of type %s" target_type
@@ -261,12 +166,6 @@ struct
261166
262167 let emit_unassume man =
263168 let es = NH. find_all invs man.node in
264- let es = D. fold (fun pre acc ->
265- match NH. find_option pre_invs man.node with
266- | Some eh -> EH. find_all eh pre @ acc
267- | None -> acc
268- ) man.local es
269- in
270169 match es with
271170 | x :: xs ->
272171 let e = List. fold_left (fun a {exp = b ; _} -> Cil. (BinOp (LAnd , a, b, intType))) x.exp xs in
@@ -277,10 +176,9 @@ struct
277176 man.emit (Unassume {exp = e; tokens});
278177 List. iter WideningTokenLifter. add tokens
279178 )
280- );
281- man.local
179+ )
282180 | [] ->
283- man.local
181+ ()
284182
285183 let assign man lv e =
286184 emit_unassume man
@@ -289,17 +187,7 @@ struct
289187 emit_unassume man
290188
291189 let body man fd =
292- let pres = FH. find_all fun_pres fd in
293- let st = List. fold_left (fun acc pre ->
294- (* M.debug ~category:Witness "%a precondition %a evaluated to %a" CilType.Fundec.pretty fd CilType.Exp.pretty pre Queries.ID.pretty v; *)
295- if Queries. eval_bool (Analyses. ask_of_man man) pre = `Lifted true then
296- D. add pre acc
297- else
298- acc
299- ) (D. empty () ) pres
300- in
301-
302- emit_unassume {man with local = st} (* doesn't query, so no need to redefine ask *)
190+ emit_unassume man
303191
304192 let asm man =
305193 emit_unassume man
@@ -310,9 +198,6 @@ struct
310198 let special man lv f args =
311199 emit_unassume man
312200
313- let enter man lv f args =
314- [(man.local, D. empty () )]
315-
316201 let combine_env man lval fexp f args fc au f_ask =
317202 man.local (* not here because isn't final transfer function on edge *)
318203
0 commit comments