@@ -59,25 +59,31 @@ struct
5959
6060 let name () = " strong protection * weak protection"
6161
62- let get ~write protection (s ,w ) =
62+ let get ~kind protection (s ,w ) =
6363 let (rw, w) = match protection with
6464 | Queries.Protection. Strong -> s
6565 | Weak -> w
6666 in
67- if write then w else rw
67+ match kind with
68+ | Queries.ProtectionKind. Write -> w
69+ | ReadWrite -> rw
6870 end
6971
7072 (* * Collects information about which variables are protected by which mutexes *)
7173 module GProtecting : sig
7274 include Lattice. S
73- val make : write : bool -> recovered :bool -> MustLockset .t -> t
74- val get : write : bool -> Queries.Protection .t -> t -> MustLockset .t
75+ val make : kind : Queries . ProtectionKind . t -> recovered :bool -> MustLockset .t -> t
76+ val get : kind : Queries . ProtectionKind . t -> Queries.Protection .t -> t -> MustLockset .t
7577 end = struct
7678 include MakeP (MustLockset )
7779
78- let make ~write ~recovered locks =
80+ let make ~kind ~recovered locks =
7981 (* If the access is not a write, set to T so intersection with current write-protecting is identity *)
80- let wlocks = if write then locks else MustLockset. all () in
82+ let wlocks =
83+ match kind with
84+ | Queries.ProtectionKind. Write -> locks
85+ | ReadWrite -> MustLockset. all ()
86+ in
8187 if recovered then
8288 (* If we are in single-threaded mode again, this does not need to be added to set of mutexes protecting in mt-mode only *)
8389 ((locks, wlocks), (MustLockset. all () , MustLockset. all () ))
@@ -89,17 +95,16 @@ struct
8995 (* * Collects information about which mutex protects which variable *)
9096 module GProtected : sig
9197 include Lattice. S
92- val make : write : bool -> VarSet .t -> t
93- val get : write : bool -> Queries.Protection .t -> t -> VarSet .t
98+ val make : kind : Queries . ProtectionKind . t -> VarSet .t -> t
99+ val get : kind : Queries . ProtectionKind . t -> Queries.Protection .t -> t -> VarSet .t
94100 end = struct
95101 include MakeP (VarSet )
96102
97- let make ~write vs =
103+ let make ~kind vs =
98104 let vs_empty = VarSet. empty () in
99- if write then
100- ((vs_empty, vs), (vs_empty, vs))
101- else
102- ((vs, vs_empty), (vs, vs_empty))
105+ match kind with
106+ | Queries.ProtectionKind. Write -> ((vs_empty, vs), (vs_empty, vs))
107+ | ReadWrite -> ((vs, vs_empty), (vs, vs_empty))
103108 end
104109
105110 module G =
@@ -198,43 +203,43 @@ struct
198203 let query (man : (D.t, _, _, V.t) man ) (type a ) (q : a Queries.t ): a Queries.result =
199204 let ls, m = man.local in
200205 (* get the set of mutexes protecting the variable v in the given mode *)
201- let protecting ~write mode v = GProtecting. get ~write mode (G. protecting (man.global (V. protecting v))) in
206+ let protecting ~kind mode v = GProtecting. get ~kind mode (G. protecting (man.global (V. protecting v))) in
202207 match q with
203208 | Queries. MayBePublic _ when MustLocksetRW. is_all ls -> false
204- | Queries. MayBePublic {global =v ; write ; protection} ->
209+ | Queries. MayBePublic {global =v ; kind ; protection} ->
205210 let held_locks = MustLocksetRW. to_must_lockset (MustLocksetRW. filter snd ls) in
206- let protecting = protecting ~write protection v in
211+ let protecting = protecting ~kind protection v in
207212 (* TODO: unsound in 29/24, why did we do this before? *)
208213 (* if Mutexes.mem verifier_atomic (Lockset.export_locks man.local) then
209214 false
210215 else *)
211216 MustLockset. disjoint held_locks protecting
212217 | Queries. MayBePublicWithout _ when MustLocksetRW. is_all ls -> false
213- | Queries. MayBePublicWithout {global =v ; write ; without_mutex; protection} ->
218+ | Queries. MayBePublicWithout {global =v ; kind ; without_mutex; protection} ->
214219 let held_locks = MustLockset. remove without_mutex (MustLocksetRW. to_must_lockset ls) in
215- let protecting = protecting ~write protection v in
220+ let protecting = protecting ~kind protection v in
216221 (* TODO: unsound in 29/24, why did we do this before? *)
217222 (* if Mutexes.mem verifier_atomic (Lockset.export_locks (Lockset.remove (without_mutex, true) man.local)) then
218223 false
219224 else *)
220225 MustLockset. disjoint held_locks protecting
221- | Queries. MustBeProtectedBy {mutex = ml ; global =v ; write ; protection} ->
222- let protecting = protecting ~write protection v in
226+ | Queries. MustBeProtectedBy {mutex = ml ; global =v ; kind ; protection} ->
227+ let protecting = protecting ~kind protection v in
223228 (* TODO: unsound in 29/24, why did we do this before? *)
224229 (* if LockDomain.Addr.equal mutex (LockDomain.Addr.of_var LF.verifier_atomic_var) then
225230 true
226231 else *)
227232 MustLockset. mem ml protecting
228- | Queries. MustProtectingLocks {global; write } ->
229- protecting ~write Strong global
233+ | Queries. MustProtectingLocks {global; kind } ->
234+ protecting ~kind Strong global
230235 | Queries. MustLockset ->
231236 let held_locks = MustLocksetRW. to_must_lockset (MustLocksetRW. filter snd ls) in
232237 held_locks
233238 | Queries. MustBeAtomic ->
234239 let held_locks = MustLocksetRW. to_must_lockset (MustLocksetRW. filter snd ls) in
235240 MustLockset. mem (LF. verifier_atomic_var, `NoOffset ) held_locks (* TODO: Mval.of_var *)
236- | Queries. MustProtectedVars {mutex; write } ->
237- let protected = GProtected. get ~write Strong (G. protected (man.global (V. protected mutex))) in
241+ | Queries. MustProtectedVars {mutex; kind } ->
242+ let protected = GProtected. get ~kind Strong (G. protected (man.global (V. protected mutex))) in
238243 VarSet. fold (fun v acc ->
239244 Queries.VS. add v acc
240245 ) protected (Queries.VS. empty () )
@@ -245,13 +250,13 @@ struct
245250 begin match g with
246251 | `Left g' -> (* protecting *)
247252 if GobConfig. get_bool " dbg.print_protection" then (
248- let protecting = GProtecting. get ~write: false Strong (G. protecting (man.global g)) in (* readwrite protecting *)
253+ let protecting = GProtecting. get ~kind: ReadWrite Strong (G. protecting (man.global g)) in (* readwrite protecting *)
249254 let s = MustLockset. cardinal protecting in
250255 M. info_noloc ~category: Race " Variable %a read-write protected by %d mutex(es): %a" CilType.Varinfo. pretty g' s MustLockset. pretty protecting
251256 )
252257 | `Right m -> (* protected *)
253258 if GobConfig. get_bool " dbg.print_protection" then (
254- let protected = GProtected. get ~write: false Strong (G. protected (man.global g)) in (* readwrite protected *)
259+ let protected = GProtected. get ~kind: ReadWrite Strong (G. protected (man.global g)) in (* readwrite protected *)
255260 let s = VarSet. cardinal protected in
256261 max_protected := max ! max_protected s;
257262 sum_protected := ! sum_protected + s;
@@ -293,21 +298,21 @@ struct
293298 | Some v ->
294299 if not (MustLocksetRW. is_all (fst oman.local)) then
295300 let locks = MustLocksetRW. to_must_lockset (MustLocksetRW. filter snd (fst oman.local)) in
296- let write = match kind with
297- | Write | Free -> true
298- | Read -> false
301+ let kind = match kind with
302+ | Write | Free -> Queries.ProtectionKind. Write
303+ | Read -> ReadWrite
299304 | Call
300- | Spawn -> false (* TODO: nonsense? *)
305+ | Spawn -> ReadWrite (* TODO: nonsense? *)
301306 in
302- let s = GProtecting. make ~write ~recovered: is_recovered_to_st locks in
307+ let s = GProtecting. make ~kind ~recovered: is_recovered_to_st locks in
303308 man.sideg (V. protecting v) (G. create_protecting s);
304309
305310 if ! AnalysisState. postsolving then (
306- let protecting mode = GProtecting. get ~write mode (G. protecting (man.global (V. protecting v))) in
311+ let protecting mode = GProtecting. get ~kind mode (G. protecting (man.global (V. protecting v))) in
307312 let held_strong = protecting Strong in
308313 let held_weak = protecting Weak in
309314 let vs = VarSet. singleton v in
310- let protected = G. create_protected @@ GProtected. make ~write vs in
315+ let protected = G. create_protected @@ GProtected. make ~kind vs in
311316 MustLockset. iter (fun ml -> man.sideg (V. protected ml) protected) held_strong;
312317 (* If the mutex set here is top, it is actually not accessed *)
313318 if is_recovered_to_st && not @@ MustLockset. is_all held_weak then
0 commit comments