Skip to content

Commit a0bb640

Browse files
Merge pull request #595 from goblint/mhp-analysis
Extract MHP analysis, simplify printing in race output
2 parents 756ee81 + 352c70e commit a0bb640

File tree

11 files changed

+69
-21
lines changed

11 files changed

+69
-21
lines changed

src/analyses/mHPAnalysis.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(** MHP access analysis. *)
2+
open Prelude.Ana
3+
open Analyses
4+
5+
module Spec =
6+
struct
7+
include UnitAnalysis.Spec
8+
let name () = "mhp"
9+
10+
module A =
11+
struct
12+
include MHP
13+
let name () = "mhp"
14+
let may_race = MHP.may_happen_in_parallel
15+
let should_print _ = true
16+
end
17+
18+
let access ctx e vo w: MHP.t =
19+
{
20+
tid = ctx.ask CurrentThreadId;
21+
created = ctx.ask CreatedThreads;
22+
must_joined = ctx.ask MustJoinedThreads
23+
}
24+
end
25+
26+
let _ =
27+
MCP.register_analysis (module Spec : MCPSpec)

src/analyses/threadId.ml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,20 @@ struct
9696

9797
module A =
9898
struct
99-
(* Also contains MHP in addition to unique thread. *)
100-
include Printable.Prod (Printable.Option (ThreadLifted) (struct let name = "nonunique" end)) (MHP)
101-
let name () = "thread * mhp"
99+
include Printable.Option (ThreadLifted) (struct let name = "nonunique" end)
100+
let name () = "thread"
102101
let may_race (t1: t) (t2: t) = match t1, t2 with
103-
| (Some t1, _), (Some t2, _) when ThreadLifted.equal t1 t2 -> false
104-
| (_, mhp1), (_, mhp2) when not (MHP.may_happen_in_parallel mhp1 mhp2) -> false
105-
| (_, _), (_, _) -> true
106-
let should_print _ = true
102+
| Some t1, Some t2 when ThreadLifted.equal t1 t2 -> false (* only unique threads *)
103+
| _, _ -> true
104+
let should_print = Option.is_some
107105
end
106+
108107
let access ctx e vo w =
109-
let unique =
110-
if is_unique ctx then
111-
let tid = fst ctx.local in
112-
Some tid
113-
else
114-
None
115-
in
116-
let mhp: MHP.t = {tid = fst ctx.local; created = created ctx.local; must_joined = ctx.ask MustJoinedThreads} in
117-
(unique, mhp)
108+
if is_unique ctx then
109+
let tid = fst ctx.local in
110+
Some tid
111+
else
112+
None
118113

119114
let threadenter ctx lval f args =
120115
let+ tid = create_tid ctx.local ctx.prev_node f in
File renamed without changes.

src/cdomains/mHP.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ type t = {
99
} [@@deriving eq, ord, hash]
1010

1111
let pretty () {tid; created; must_joined} =
12-
Pretty.dprintf "{ tid=%a; created=%a; must_joined=%a }" ThreadIdDomain.ThreadLifted.pretty tid ConcDomain.ThreadSet.pretty created ConcDomain.ThreadSet.pretty must_joined
12+
let tid_doc = Some (Pretty.dprintf "tid=%a" ThreadIdDomain.ThreadLifted.pretty tid) in
13+
(* avoid useless empty sets in race output *)
14+
let created_doc =
15+
if ConcDomain.ThreadSet.is_empty created then
16+
None
17+
else
18+
Some (Pretty.dprintf "created=%a" ConcDomain.ThreadSet.pretty created)
19+
in
20+
let must_joined_doc =
21+
if ConcDomain.ThreadSet.is_empty must_joined then
22+
None
23+
else
24+
Some (Pretty.dprintf "must_joined=%a" ConcDomain.ThreadSet.pretty must_joined)
25+
in
26+
let docs = List.filter_map (fun doc -> doc) [tid_doc; created_doc; must_joined_doc] in
27+
Pretty.dprintf "{%a}" (Pretty.d_list "; " Pretty.insert) docs
1328

1429
include Printable.SimplePretty (
1530
struct

src/cdomains/threadIdDomain.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ struct
9898
end
9999
include Printable.Prod (P) (S)
100100

101+
let pretty () (p, s) =
102+
let p = List.rev p in (* show in "unreversed" order *)
103+
if S.is_empty s then
104+
P.pretty () p (* hide empty set *)
105+
else
106+
Pretty.dprintf "%a, %a" P.pretty p S.pretty s
107+
108+
let show x = Pretty.sprint ~width:max_int (pretty () x)
109+
101110
module D =
102111
struct
103112
include S

src/util/options.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
"items": { "type": "string" },
257257
"default": [
258258
"expRelation", "base", "threadid", "threadflag", "threadreturn",
259-
"escape", "mutex", "access", "mallocWrapper"
259+
"escape", "mutex", "access", "mallocWrapper", "mhp"
260260
]
261261
},
262262
"path_sens": {

tests/regression/10-synch/13-two_threads_nr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PARAM: --set ana.activated[+] threadJoins
1+
// PARAM: --set ana.activated[+] mhp --set ana.activated[+] threadJoins
22
#include <pthread.h>
33
#include <stdio.h>
44

tests/regression/10-synch/15-join_other_nr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PARAM: --set ana.activated[+] threadJoins
1+
// PARAM: --set ana.activated[+] mhp --set ana.activated[+] threadJoins
22
#include <pthread.h>
33
#include <stdio.h>
44

tests/regression/53-races-mhp/01-not-created.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// PARAM: --set ana.activated[+] mhp
12
#include <pthread.h>
23
#include <assert.h>
34

tests/regression/53-races-mhp/02-join.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//PARAM: --set ana.activated[+] threadJoins
1+
//PARAM: --set ana.activated[+] mhp --set ana.activated[+] threadJoins
22
#include <pthread.h>
33
#include <assert.h>
44

0 commit comments

Comments
 (0)