Skip to content

Commit 8a95c8a

Browse files
committed
Add multiple flag to ThreadCreate
1 parent 670e7cf commit 8a95c8a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/analyses/base.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,8 +1953,8 @@ struct
19531953

19541954

19551955

1956-
let forkfun (ctx:(D.t, G.t, C.t, V.t) Analyses.ctx) (lv: lval option) (f: varinfo) (args: exp list) : (lval option * varinfo * exp list) list * bool =
1957-
let create_thread lval arg v =
1956+
let forkfun (ctx:(D.t, G.t, C.t, V.t) Analyses.ctx) (lv: lval option) (f: varinfo) (args: exp list) : (lval option * varinfo * exp list * bool) list =
1957+
let create_thread ~multiple lval arg v =
19581958
try
19591959
(* try to get function declaration *)
19601960
let fd = Cilfacade.find_varinfo_fundec v in
@@ -1963,7 +1963,7 @@ struct
19631963
| Some x -> [x]
19641964
| None -> List.map (fun x -> MyCFG.unknown_exp) fd.sformals
19651965
in
1966-
Some (lval, v, args)
1966+
Some (lval, v, args, multiple)
19671967
with Not_found ->
19681968
if LF.use_special f.vname then None (* we handle this function *)
19691969
else if isFunctionType v.vtype then
@@ -1973,7 +1973,7 @@ struct
19731973
| Some x -> [x]
19741974
| None -> List.map (fun x -> MyCFG.unknown_exp) (Cil.argsToList v_args)
19751975
in
1976-
Some (lval, v, args)
1976+
Some (lval, v, args, multiple)
19771977
else (
19781978
M.debug ~category:Analyzer "Not creating a thread from %s because its type is %a" v.vname d_type v.vtype;
19791979
None
@@ -1982,7 +1982,7 @@ struct
19821982
let desc = LF.find f in
19831983
match desc.special args, f.vname with
19841984
(* handling thread creations *)
1985-
| ThreadCreate { thread = id; start_routine = start; arg = ptc_arg }, _ -> begin
1985+
| ThreadCreate { thread = id; start_routine = start; arg = ptc_arg; multiple }, _ -> begin
19861986
(* extra sync so that we do not analyze new threads with bottom global invariant *)
19871987
publish_all ctx `Thread;
19881988
(* Collect the threads. *)
@@ -1994,7 +1994,7 @@ struct
19941994
else
19951995
start_funvars
19961996
in
1997-
List.filter_map (create_thread (Some (Mem id, NoOffset)) (Some ptc_arg)) start_funvars_with_unknown, false
1997+
List.filter_map (create_thread ~multiple (Some (Mem id, NoOffset)) (Some ptc_arg)) start_funvars_with_unknown
19981998
end
19991999
| _, _ when get_bool "sem.unknown_function.spawn" ->
20002000
(* TODO: Remove sem.unknown_function.spawn check because it is (and should be) really done in LibraryFunctions.
@@ -2008,8 +2008,8 @@ struct
20082008
let flist = shallow_flist @ deep_flist in
20092009
let addrs = List.concat_map AD.to_var_may flist in
20102010
if addrs <> [] then M.debug ~category:Analyzer "Spawning non-unique functions from unknown function: %a" (d_list ", " CilType.Varinfo.pretty) addrs;
2011-
List.filter_map (create_thread None None) addrs, true
2012-
| _, _ -> [], false
2011+
List.filter_map (create_thread ~multiple:true None None) addrs
2012+
| _, _ -> []
20132013

20142014
let assert_fn ctx e refine =
20152015
(* make the state meet the assertion in the rest of the code *)
@@ -2140,9 +2140,9 @@ struct
21402140
let addr = eval_lv (Analyses.ask_of_ctx ctx) ctx.global ctx.local lval in
21412141
(addr, AD.type_of addr)
21422142
in
2143-
let forks, multiple = forkfun ctx lv f args in
2144-
if M.tracing then if not (List.is_empty forks) then M.tracel "spawn" "Base.special %s: spawning functions %a\n" f.vname (d_list "," CilType.Varinfo.pretty) (List.map BatTuple.Tuple3.second forks);
2145-
List.iter (BatTuple.Tuple3.uncurry (ctx.spawn ~multiple)) forks;
2143+
let forks = forkfun ctx lv f args in
2144+
if M.tracing then if not (List.is_empty forks) then M.tracel "spawn" "Base.special %s: spawning functions %a\n" f.vname (d_list "," CilType.Varinfo.pretty) (List.map BatTuple.Tuple4.second forks);
2145+
List.iter (fun (lval, f, args, multiple) -> ctx.spawn ~multiple lval f args) forks;
21462146
let st: store = ctx.local in
21472147
let gs = ctx.global in
21482148
let desc = LF.find f in

src/analyses/libraryDesc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type special =
5353
| Assert of { exp: Cil.exp; check: bool; refine: bool; }
5454
| Lock of { lock: Cil.exp; try_: bool; write: bool; return_on_success: bool; }
5555
| Unlock of Cil.exp
56-
| ThreadCreate of { thread: Cil.exp; start_routine: Cil.exp; arg: Cil.exp; }
56+
| ThreadCreate of { thread: Cil.exp; start_routine: Cil.exp; arg: Cil.exp; multiple: bool }
5757
| ThreadJoin of { thread: Cil.exp; ret_var: Cil.exp; }
5858
| ThreadExit of { ret_val: Cil.exp; }
5959
| Signal of Cil.exp

src/analyses/libraryFunctions.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ let posix_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
422422

423423
(** Pthread functions. *)
424424
let pthread_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
425-
("pthread_create", special [__ "thread" [w]; drop "attr" [r]; __ "start_routine" [s]; __ "arg" []] @@ fun thread start_routine arg -> ThreadCreate { thread; start_routine; arg }); (* For precision purposes arg is not considered accessed here. Instead all accesses (if any) come from actually analyzing start_routine. *)
425+
("pthread_create", special [__ "thread" [w]; drop "attr" [r]; __ "start_routine" [s]; __ "arg" []] @@ fun thread start_routine arg -> ThreadCreate { thread; start_routine; arg; multiple = false }); (* For precision purposes arg is not considered accessed here. Instead all accesses (if any) come from actually analyzing start_routine. *)
426426
("pthread_exit", special [__ "retval" []] @@ fun retval -> ThreadExit { ret_val = retval }); (* Doesn't dereference the void* itself, but just passes to pthread_join. *)
427427
("pthread_join", special [__ "thread" []; __ "retval" [w]] @@ fun thread retval -> ThreadJoin {thread; ret_var = retval});
428428
("pthread_kill", unknown [drop "thread" []; drop "sig" []]);
@@ -1007,7 +1007,7 @@ let rtnl_lock = AddrOf (Cil.var (Cilfacade.create_var (makeGlobalVar "[rtnl_lock
10071007

10081008
(** LDV Klever functions. *)
10091009
let klever_descs_list: (string * LibraryDesc.t) list = LibraryDsl.[
1010-
("pthread_create_N", special [__ "thread" [w]; drop "attr" [r]; __ "start_routine" [s]; __ "arg" []] @@ fun thread start_routine arg -> ThreadCreate { thread; start_routine; arg }); (* TODO: add multiple flag to ThreadCreate *)
1010+
("pthread_create_N", special [__ "thread" [w]; drop "attr" [r]; __ "start_routine" [s]; __ "arg" []] @@ fun thread start_routine arg -> ThreadCreate { thread; start_routine; arg; multiple = true });
10111011
("pthread_join_N", special [__ "thread" []; __ "retval" [w]] @@ fun thread retval -> ThreadJoin {thread; ret_var = retval});
10121012
("ldv_mutex_model_lock", special [__ "lock" []; drop "sign" []] @@ fun lock -> Lock { lock; try_ = get_bool "sem.lock.fail"; write = true; return_on_success = true });
10131013
("ldv_mutex_model_unlock", special [__ "lock" []; drop "sign" []] @@ fun lock -> Unlock lock);

0 commit comments

Comments
 (0)