@@ -17,13 +17,36 @@ struct
1717 module D = Lattice. Unit
1818 module C = Lattice. Unit
1919
20+ (* Two global invariants:
21+ 1. (lval, type) -> accesses -- used for warnings
22+ 2. varinfo -> set of (lval, type) -- used for IterSysVars Global *)
23+
24+ module V0 = Printable. Prod (Access. LVOpt ) (Access. T )
25+ module V =
26+ struct
27+ include Printable. Either (V0 ) (CilType. Varinfo )
28+ let access x = `Left x
29+ let vars x = `Right x
30+ end
31+
32+ module V0Set = SetDomain. Make (V0 )
2033 module G =
2134 struct
22- include Access. AS
35+ include Lattice. Lift2 (Access. AS ) (V0Set ) (Printable. DefaultNames )
36+
37+ let access = function
38+ | `Bot -> Access.AS. bot ()
39+ | `Lifted1 x -> x
40+ | _ -> failwith " Access.access"
41+ let vars = function
42+ | `Bot -> V0Set. bot ()
43+ | `Lifted2 x -> x
44+ | _ -> failwith " Access.vars"
45+ let create_access access = `Lifted1 access
46+ let create_vars vars = `Lifted2 vars
2347
2448 let leq x y = ! GU. postsolving || leq x y (* HACK: to pass verify*)
2549 end
26- module V = Printable. Prod (Access. LVOpt ) (Access. T )
2750
2851 let safe = ref 0
2952 let vulnerable = ref 0
@@ -34,14 +57,28 @@ struct
3457 vulnerable := 0 ;
3558 unsafe := 0
3659
60+ let side_vars ctx lv_opt ty =
61+ match lv_opt with
62+ | Some (v , _ ) ->
63+ let d =
64+ if ! GU. should_warn then
65+ G. create_vars (V0Set. singleton (lv_opt, ty))
66+ else
67+ G. bot () (* HACK: just to pass validation with MCP DomVariantLattice *)
68+ in
69+ ctx.sideg (V. vars v) d;
70+ | None ->
71+ ()
72+
3773 let side_access ctx ty lv_opt (conf , w , loc , e , a ) =
3874 let d =
3975 if ! GU. should_warn then
40- Access.AS. singleton (conf, w, loc, e, a)
76+ G. create_access ( Access.AS. singleton (conf, w, loc, e, a) )
4177 else
4278 G. bot () (* HACK: just to pass validation with MCP DomVariantLattice *)
4379 in
44- ctx.sideg (lv_opt, ty) d
80+ ctx.sideg (V. access (lv_opt, ty)) d;
81+ side_vars ctx lv_opt ty
4582
4683 let do_access (ctx : (D.t, G.t, C.t, V.t) ctx ) (w :bool ) (reach :bool ) (conf :int ) (e :exp ) =
4784 let open Queries in
@@ -204,9 +241,18 @@ struct
204241 match q with
205242 | WarnGlobal g ->
206243 let g: V. t = Obj. obj g in
207- (* ignore (Pretty.printf "WarnGlobal %a\n" CilType.Varinfo.pretty g); *)
208- let accs = ctx.global g in
209- Stats. time " access" (Access. warn_global safe vulnerable unsafe g) accs
244+ begin match g with
245+ | `Left g' -> (* accesses *)
246+ (* ignore (Pretty.printf "WarnGlobal %a\n" CilType.Varinfo.pretty g); *)
247+ let accs = G. access (ctx.global g) in
248+ Stats. time " access" (Access. warn_global safe vulnerable unsafe g') accs
249+ | `Right _ -> (* vars *)
250+ ()
251+ end
252+ | IterSysVars (Global g , vf ) ->
253+ V0Set. iter (fun v ->
254+ vf (Obj. repr (V. access v))
255+ ) (G. vars (ctx.global (V. vars g)))
210256 | _ -> Queries.Result. top q
211257
212258 let finalize () =
0 commit comments