Skip to content

Commit a9c22ce

Browse files
committed
Add basic threadAccess analysis
1 parent 7f216c4 commit a9c22ce

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/analyses/accessAnalysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct
2929
let init _ =
3030
collect_local := get_bool "witness.yaml.enabled" && get_bool "witness.invariant.accessed";
3131
let activated = get_string_list "ana.activated" in
32-
emit_single_threaded := List.mem (ModifiedSinceSetjmp.Spec.name ()) activated || List.mem (PoisonVariables.Spec.name ()) activated || List.mem (UseAfterFree.Spec.name ()) activated (* TODO: some of these don't have access as dependency *)
32+
emit_single_threaded := List.mem (ModifiedSinceSetjmp.Spec.name ()) activated || List.mem (PoisonVariables.Spec.name ()) activated || List.mem (UseAfterFree.Spec.name ()) activated || List.mem (ThreadAccess.Spec.name ()) activated (* TODO: some of these don't have access as dependency *)
3333

3434
let do_access (man: (D.t, G.t, C.t, V.t) man) (kind:AccessKind.t) (reach:bool) (e:exp) =
3535
if M.tracing then M.trace "access" "do_access %a %a %B" d_exp e AccessKind.pretty kind reach;

src/analyses/threadAccess.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
open Analyses
2+
3+
module Spec =
4+
struct
5+
include UnitAnalysis.Spec
6+
7+
let name () = "threadAccess"
8+
9+
module V =
10+
struct
11+
include CilType.Varinfo
12+
let is_write_only _ = false
13+
end
14+
15+
module G = ConcDomain.ThreadSet
16+
17+
let query man (type a) (q: a Queries.t): a Queries.result =
18+
match q with
19+
| MayBePublic {global; _} ->
20+
if G.cardinal (man.global global) = 1 then
21+
false
22+
else
23+
Queries.Result.top q
24+
| _ -> Queries.Result.top q
25+
26+
let event man e oman =
27+
match e with
28+
| Events.Access {ad; _} ->
29+
Queries.AD.iter (function
30+
| Queries.AD.Addr.Addr (v, _) when v.vglob ->
31+
begin match man.ask CurrentThreadId with
32+
| `Lifted tid -> man.sideg v (G.singleton tid)
33+
| _ -> () (* TODO: what here? *)
34+
end
35+
| _ -> ()
36+
) ad
37+
| _ ->
38+
man.local
39+
end
40+
41+
let _ =
42+
MCP.register_analysis ~dep:["access"] (module Spec : MCPSpec)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// PARAM: --set ana.activated[+] threadAccess
2+
#include <signal.h>
3+
#include <goblint.h>
4+
5+
int g = 0;
6+
7+
void handler(int sig) {
8+
}
9+
10+
int main() {
11+
__goblint_check(g == 0);
12+
g = 1;
13+
__goblint_check(g == 1);
14+
signal(SIGTERM, handler);
15+
__goblint_check(g == 1);
16+
g = 2;
17+
__goblint_check(g == 2);
18+
return 0;
19+
}

0 commit comments

Comments
 (0)