Skip to content

Commit 2f80c77

Browse files
committed
Add Mutex variant to ValueDomain
1 parent 73c4fce commit 2f80c77

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/analyses/base.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ struct
429429
| `Struct s -> ValueDomain.Structs.fold (fun k v acc -> AD.join (reachable_from_value ask gs st v t description) acc) s empty
430430
| `Int _ -> empty
431431
| `Thread _ -> empty (* thread IDs are abstract and nothing known can be reached from them *)
432+
| `Mutex -> empty (* mutexes are abstract and nothing known can be reached from them *)
432433

433434
(* Get the list of addresses accessable immediately from a given address, thus
434435
* all pointers within a structure should be considered, but we don't follow
@@ -567,6 +568,7 @@ struct
567568
ValueDomain.Structs.fold f s (empty, TS.bot (), false)
568569
| `Int _ -> (empty, TS.bot (), false)
569570
| `Thread _ -> (empty, TS.bot (), false) (* TODO: is this right? *)
571+
| `Mutex -> (empty, TS.bot (), false) (* TODO: is this right? *)
570572
in
571573
reachable_from_value (get (Analyses.ask_of_ctx ctx) ctx.global ctx.local adr None)
572574
in

src/cdomains/valueDomain.ml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ module rec Compound: S with type t = [
7878
| `Array of CArrays.t
7979
| `Blob of Blobs.t
8080
| `Thread of Threads.t
81+
| `Mutex
8182
| `Bot
8283
] and type offs = (fieldinfo,IndexDomain.t) Lval.offs =
8384
struct
@@ -90,6 +91,7 @@ struct
9091
| `Array of CArrays.t
9192
| `Blob of Blobs.t
9293
| `Thread of Threads.t
94+
| `Mutex
9395
| `Bot
9496
] [@@deriving eq, ord, hash]
9597

@@ -106,6 +108,7 @@ struct
106108

107109
let rec bot_value (t: typ): t =
108110
match t with
111+
| _ when is_mutex_type t -> `Mutex
109112
| TInt _ -> `Bot (*`Int (ID.bot ()) -- should be lower than any int or address*)
110113
| TPtr _ -> `Address (AD.bot ())
111114
| TComp ({cstruct=true; _} as ci,_) -> `Struct (Structs.create (fun fd -> bot_value fd.ftype) ci)
@@ -128,12 +131,13 @@ struct
128131
| `Array x -> CArrays.is_bot x
129132
| `Blob x -> Blobs.is_bot x
130133
| `Thread x -> Threads.is_bot x
134+
| `Mutex -> false
131135
| `Bot -> true
132136
| `Top -> false
133137

134138
let rec init_value (t: typ): t = (* top_value is not used here because structs, blob etc will not contain the right members *)
135139
match t with
136-
| t when is_mutex_type t -> `Bot (* use `Bot instead of `Top to avoid unknown value escape warnings *)
140+
| t when is_mutex_type t -> `Mutex
137141
| TInt (ik,_) -> `Int (ID.top_of ik)
138142
| TPtr _ -> `Address AD.top_ptr
139143
| TComp ({cstruct=true; _} as ci,_) -> `Struct (Structs.create (fun fd -> init_value fd.ftype) ci)
@@ -149,6 +153,7 @@ struct
149153

150154
let rec top_value (t: typ): t =
151155
match t with
156+
| _ when is_mutex_type t -> `Mutex
152157
| TInt (ik,_) -> `Int (ID.(cast_to ik (top_of ik)))
153158
| TPtr _ -> `Address AD.top_ptr
154159
| TComp ({cstruct=true; _} as ci,_) -> `Struct (Structs.create (fun fd -> top_value fd.ftype) ci)
@@ -170,11 +175,13 @@ struct
170175
| `Array x -> CArrays.is_top x
171176
| `Blob x -> Blobs.is_top x
172177
| `Thread x -> Threads.is_top x
178+
| `Mutex -> false
173179
| `Top -> true
174180
| `Bot -> false
175181

176182
let rec zero_init_value (t:typ): t =
177183
match t with
184+
| _ when is_mutex_type t -> `Mutex
178185
| TInt (ikind, _) -> `Int (ID.of_int ikind BI.zero)
179186
| TPtr _ -> `Address AD.null_ptr
180187
| TComp ({cstruct=true; _} as ci,_) -> `Struct (Structs.create (fun fd -> zero_init_value fd.ftype) ci)
@@ -198,7 +205,7 @@ struct
198205
| _ -> `Top
199206

200207
let tag_name : t -> string = function
201-
| `Top -> "Top" | `Int _ -> "Int" | `Address _ -> "Address" | `Struct _ -> "Struct" | `Union _ -> "Union" | `Array _ -> "Array" | `Blob _ -> "Blob" | `Thread _ -> "Thread" | `Bot -> "Bot"
208+
| `Top -> "Top" | `Int _ -> "Int" | `Address _ -> "Address" | `Struct _ -> "Struct" | `Union _ -> "Union" | `Array _ -> "Array" | `Blob _ -> "Blob" | `Thread _ -> "Thread" | `Mutex -> "Mutex" | `Bot -> "Bot"
202209

203210
include Printable.Std
204211
let name () = "compound"
@@ -222,6 +229,7 @@ struct
222229
| `Array n -> CArrays.pretty () n
223230
| `Blob n -> Blobs.pretty () n
224231
| `Thread n -> Threads.pretty () n
232+
| `Mutex -> text "mutex"
225233
| `Bot -> text bot_name
226234
| `Top -> text top_name
227235

@@ -234,6 +242,7 @@ struct
234242
| `Array n -> CArrays.show n
235243
| `Blob n -> Blobs.show n
236244
| `Thread n -> Threads.show n
245+
| `Mutex -> "mutex"
237246
| `Bot -> bot_name
238247
| `Top -> top_name
239248

@@ -342,7 +351,8 @@ struct
342351
(*if v = `Bot || (match torg with Some x -> is_safe_cast t x | None -> false) then v else*)
343352
match v with
344353
| `Bot
345-
| `Thread _ ->
354+
| `Thread _
355+
| `Mutex ->
346356
v
347357
| _ ->
348358
let log_top (_,l,_,_) = Messages.tracel "cast" "log_top at %d: %a to %a is top!\n" l pretty v d_type t in
@@ -445,6 +455,7 @@ struct
445455
| (`Thread x, `Thread y) -> Threads.leq x y
446456
| (`Int x, `Thread y) -> true
447457
| (`Address x, `Thread y) -> true
458+
| (`Mutex, `Mutex) -> true
448459
| _ -> warn_type "leq" x y; false
449460

450461
let rec join x y =
@@ -475,6 +486,7 @@ struct
475486
| (`Address x, `Thread y)
476487
| (`Thread y, `Address x) ->
477488
`Thread y (* TODO: ignores address! *)
489+
| (`Mutex, `Mutex) -> `Mutex
478490
| _ ->
479491
warn_type "join" x y;
480492
`Top
@@ -509,6 +521,7 @@ struct
509521
| (`Address x, `Thread y)
510522
| (`Thread y, `Address x) ->
511523
`Thread y (* TODO: ignores address! *)
524+
| (`Mutex, `Mutex) -> `Mutex
512525
| _ ->
513526
warn_type "join" x y;
514527
`Top
@@ -540,6 +553,7 @@ struct
540553
| (`Address x, `Thread y)
541554
| (`Thread y, `Address x) ->
542555
`Thread y (* TODO: ignores address! *)
556+
| (`Mutex, `Mutex) -> `Mutex
543557
| _ ->
544558
warn_type "widen" x y;
545559
`Top
@@ -566,6 +580,7 @@ struct
566580
| (`Thread x, `Thread y) -> Threads.leq x y
567581
| (`Int x, `Thread y) -> true
568582
| (`Address x, `Thread y) -> true
583+
| (`Mutex, `Mutex) -> true
569584
| _ -> warn_type "leq" x y; false
570585

571586
let rec meet x y =
@@ -589,6 +604,7 @@ struct
589604
| (`Address x, `Thread y)
590605
| (`Thread y, `Address x) ->
591606
`Address x (* TODO: ignores thread! *)
607+
| (`Mutex, `Mutex) -> `Mutex
592608
| _ ->
593609
warn_type "meet" x y;
594610
`Bot
@@ -619,6 +635,7 @@ struct
619635
| (`Address x, `Thread y)
620636
| (`Thread y, `Address x) ->
621637
`Thread y (* TODO: ignores address! *)
638+
| (`Mutex, `Mutex) -> `Mutex
622639
| _ ->
623640
warn_type "widen" x y;
624641
`Top
@@ -640,6 +657,7 @@ struct
640657
| (`Address x, `Thread y)
641658
| (`Thread y, `Address x) ->
642659
`Address x (* TODO: ignores thread! *)
660+
| (`Mutex, `Mutex) -> `Mutex
643661
| x, `Top | `Top, x -> x
644662
| x, `Bot | `Bot, x -> `Bot
645663
| _ ->
@@ -854,8 +872,8 @@ struct
854872
let mu = function `Blob (`Blob (y, s', orig), s, orig2) -> `Blob (y, ID.join s s',orig) | x -> x in
855873
let r =
856874
match x, offs with
857-
| _, _ when is_mutex_type t -> (* hide mutex structure contents, not updated anyway *)
858-
`Bot (* use `Bot instead of `Top to avoid unknown value escape warnings *)
875+
| `Mutex, _ -> (* hide mutex structure contents, not updated anyway *)
876+
`Mutex
859877
| `Blob (x,s,orig), `Index (_,ofs) ->
860878
begin
861879
let l', o' = shift_one_over l o in
@@ -1056,6 +1074,7 @@ struct
10561074
| `Array n -> CArrays.printXml f n
10571075
| `Blob n -> Blobs.printXml f n
10581076
| `Thread n -> Threads.printXml f n
1077+
| `Mutex -> BatPrintf.fprintf f "<value>\n<data>\nmutex\n</data>\n</value>\n"
10591078
| `Bot -> BatPrintf.fprintf f "<value>\n<data>\nbottom\n</data>\n</value>\n"
10601079
| `Top -> BatPrintf.fprintf f "<value>\n<data>\ntop\n</data>\n</value>\n"
10611080

@@ -1067,6 +1086,7 @@ struct
10671086
| `Array n -> CArrays.to_yojson n
10681087
| `Blob n -> Blobs.to_yojson n
10691088
| `Thread n -> Threads.to_yojson n
1089+
| `Mutex -> `String "mutex"
10701090
| `Bot -> `String ""
10711091
| `Top -> `String ""
10721092

@@ -1081,6 +1101,7 @@ struct
10811101
| `Array n -> `Array (project_arr p n)
10821102
| `Blob (v, s, z) -> `Blob (project p v, ID.project p s, z)
10831103
| `Thread n -> `Thread n
1104+
| `Mutex -> `Mutex
10841105
| `Bot -> `Bot
10851106
| `Top -> `Top
10861107
and project_addr p a =

0 commit comments

Comments
 (0)