Skip to content

Commit 5371706

Browse files
committed
Extract MHP access collecting to mhp analysis (issue #571)
1 parent e1d65b2 commit 5371706

File tree

8 files changed

+43
-19
lines changed

8 files changed

+43
-19
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
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.

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

tests/regression/53-races-mhp/03-not-created_rc.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 <stdio.h>
34

0 commit comments

Comments
 (0)