@@ -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 ) =
@@ -230,15 +141,9 @@ struct
230141 in
231142
232143 match YamlWitness. entry_type_enabled target_type, entry.entry_type with
233- | true , LocationInvariant x ->
234- unassume_location_invariant x
235- | true , LoopInvariant x ->
236- unassume_loop_invariant x
237- | true , PreconditionLoopInvariant x ->
238- unassume_precondition_loop_invariant x
239144 | true , InvariantSet x ->
240145 unassume_invariant_set x
241- | false , ( LocationInvariant _ | LoopInvariant _ | PreconditionLoopInvariant _ | InvariantSet _ ) ->
146+ | false , InvariantSet _ ->
242147 M. info_noloc ~category: Witness " disabled entry of type %s" target_type
243148 | _ ->
244149 M. warn_noloc ~category: Witness " cannot unassume entry of type %s" target_type
@@ -252,12 +157,6 @@ struct
252157
253158 let emit_unassume man =
254159 let es = NH. find_all invs man.node in
255- let es = D. fold (fun pre acc ->
256- match NH. find_option pre_invs man.node with
257- | Some eh -> EH. find_all eh pre @ acc
258- | None -> acc
259- ) man.local es
260- in
261160 match es with
262161 | x :: xs ->
263162 let e = List. fold_left (fun a {exp = b ; _} -> Cil. (BinOp (LAnd , a, b, intType))) x.exp xs in
@@ -268,10 +167,9 @@ struct
268167 man.emit (Unassume {exp = e; tokens});
269168 List. iter WideningTokenLifter. add tokens
270169 )
271- );
272- man.local
170+ )
273171 | [] ->
274- man.local
172+ ()
275173
276174 let assign man lv e =
277175 emit_unassume man
@@ -280,17 +178,7 @@ struct
280178 emit_unassume man
281179
282180 let body man fd =
283- let pres = FH. find_all fun_pres fd in
284- let st = List. fold_left (fun acc pre ->
285- (* M.debug ~category:Witness "%a precondition %a evaluated to %a" CilType.Fundec.pretty fd CilType.Exp.pretty pre Queries.ID.pretty v; *)
286- if Queries. eval_bool (Analyses. ask_of_man man) pre = `Lifted true then
287- D. add pre acc
288- else
289- acc
290- ) (D. empty () ) pres
291- in
292-
293- emit_unassume {man with local = st} (* doesn't query, so no need to redefine ask *)
181+ emit_unassume man
294182
295183 let asm man =
296184 emit_unassume man
@@ -301,9 +189,6 @@ struct
301189 let special man lv f args =
302190 emit_unassume man
303191
304- let enter man lv f args =
305- [(man.local, D. empty () )]
306-
307192 let combine_env man lval fexp f args fc au f_ask =
308193 man.local (* not here because isn't final transfer function on edge *)
309194
0 commit comments