Skip to content

Commit

Permalink
Collect thread spawns instead of doing them immediately (issue #148)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Apr 6, 2021
1 parent 8ab303c commit 266da15
Show file tree
Hide file tree
Showing 36 changed files with 100 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/analyses/arinc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ struct
let f_d = snd (Tasks.choose tasks_f) in
{ f_d with pre = d.pre }

let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
end

let _ =
Expand Down
3 changes: 2 additions & 1 deletion src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ struct
end
(* handling thread creations *)
| `ThreadCreate _ ->
D.bot () (* actual results joined via threadspawn *)
ctx.local (* actual results joined via threadspawn *)
(* handling thread joins... sort of *)
| `ThreadJoin (id,ret_var) ->
begin match (eval_rv ctx.ask gs st ret_var) with
Expand Down Expand Up @@ -2184,6 +2184,7 @@ struct
ctx.local

let threadspawn ctx (lval: lval option) (f: varinfo) (args: exp list) fctx: D.t =
(* D.join ctx.local @@ *)
match lval with
| Some lval ->
begin match ThreadId.get_current fctx.ask with
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/condVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/contain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/deadlock.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct
(* Some required states *)
let startstate _ : D.t = D.empty ()
let threadenter ctx lval f args : D.t = D.empty ()
let threadspawn ctx lval f args fctx = D.empty ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate _ : D.t = D.empty ()

(* ======== Transfer functions ======== *)
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/expRelation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/extract_arinc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ struct
let f_d = snd (Tasks.choose tasks_f) in
f_d

let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
end

let _ =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/extract_osek.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ struct

let startstate v = Pid.of_int 0L, Ctx.top (), Pred.of_node (MyCFG.Function (emptyFunction "main").svar)
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()

let init () = (* registers which functions to extract and writes out their definitions *)
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/fileUse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/flag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct

let startstate v = D.top ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

let name () = "flag"
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/flagModes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct

let startstate v = D.top ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/mallocWrapperAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

let heap_hash = Hashtbl.create 113
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/malloc_null.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ struct

let startstate v = D.empty ()
let threadenter ctx lval f args = D.empty ()
let threadspawn ctx lval f args fctx = D.empty ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.empty ()

let init () =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/mayLocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct

let startstate v = D.empty ()
let threadenter ctx lval f args = D.empty ()
let threadspawn ctx lval f args fctx = D.empty ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/mutexAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ struct
(** We just lift start state, global and dependency functions: *)
let startstate v = Lockset.empty ()
let threadenter ctx lval f args = Lockset.empty ()
let threadspawn ctx lval f args fctx = Lockset.empty ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = Lockset.empty ()

let query ctx (q:Queries.t) : Queries.Result.t =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/octagon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ struct
else `Top
| _ -> Queries.Result.top ()

let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
end


Expand Down
2 changes: 1 addition & 1 deletion src/analyses/osek.ml
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ struct
let exitstate v = D.top ()

let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local

let activate_task ctx (task_name : string) : unit =
let task = Cilfacade.getFun task_name in
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/osektransactionality.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

(** Finalization and other result printing functions: *)
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/poly.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct
let context x = if GobConfig.get_bool "exp.full-context" then x else D.bot ()

let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate _ = D.top ()
let startstate _ = D.top ()

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/region.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct

let threadenter ctx lval f args =
`Lifted (RegMap.bot ())
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local

let exitstate v = `Lifted (RegMap.bot ())

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/shapes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct
let threadenter ctx lval f args =
let st, re = ctx.local in
(LD.singleton (SHMap.top ()), Re.threadenter (re_context ctx re) lval f args)
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local

let sync_ld ask gl upd st =
let f sm (st, ds, rm, part)=
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/spec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()
end

Expand Down
4 changes: 2 additions & 2 deletions src/analyses/stackTrace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()
end

Expand Down Expand Up @@ -79,7 +79,7 @@ struct
let threadenter ctx lval f args =
D.push !Tracing.current_loc ctx.local

let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
end


Expand Down
2 changes: 1 addition & 1 deletion src/analyses/symbLocks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct

let startstate v = D.top ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

let branch ctx exp tv = ctx.local
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/termination.ml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.bot ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.bot ()
end

Expand Down
6 changes: 4 additions & 2 deletions src/analyses/threadAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct
module C = D
module G = ConcDomain.ThreadCreation

let should_join = D.equal

(* transfer functions *)
let assign ctx (lval:lval) (rval:exp) : D.t = ctx.local
let branch ctx (exp:exp) (tv:bool) : D.t = ctx.local
Expand Down Expand Up @@ -100,7 +102,7 @@ struct
| `Bot -> (false, TS.bot (), false)
in
ctx.sideg tid eff;
D.singleton tid
D.join ctx.local (D.singleton tid)
let exitstate v = D.bot ()
end

Expand Down Expand Up @@ -131,7 +133,7 @@ struct
let location x = let l = !Tracing.current_loc in l.file ^ ":" ^ string_of_int l.line ^ ":" ^ x.vname in
D.singleton (location f)

let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
end

let _ = MCP.register_analysis (module StartLocIDs : MCPSpec)
Expand Down
15 changes: 8 additions & 7 deletions src/analyses/threadEscape.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ struct
| _ -> D.bot ()

let threadspawn ctx lval f args fctx =
match args with
| [ptc_arg] ->
let escaped = fctx.local in (* reuse reachable computation from threadenter *)
if not (D.is_empty escaped) then (* avoid emitting unnecessary event *)
ctx.emit (Events.Escape escaped);
escaped
| _ -> D.bot ()
D.join ctx.local @@
match args with
| [ptc_arg] ->
let escaped = fctx.local in (* reuse reachable computation from threadenter *)
if not (D.is_empty escaped) then (* avoid emitting unnecessary event *)
ctx.emit (Events.Escape escaped);
escaped
| _ -> D.bot ()
end

let _ =
Expand Down
4 changes: 3 additions & 1 deletion src/analyses/threadFlag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct
let create_tid v =
Flag.get_multi ()

let should_join = D.equal

let body ctx f = ctx.local

let branch ctx exp tv = ctx.local
Expand Down Expand Up @@ -84,7 +86,7 @@ struct
let threadspawn ctx lval f args fctx =
if not (is_multi ctx.ask) then
ctx.emit Events.EnterMultiThreaded;
Flag.get_main ()
D.join ctx.local (Flag.get_main ())
end

let _ =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/threadId.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct
create_tid f

let threadspawn ctx lval f args fctx =
ThreadLifted.bot ()
ctx.local
end

let _ =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/threadReturn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct

let startstate v = true
let threadenter ctx lval f args = true
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

let query ctx x =
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/uninit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct

let startstate v : D.t = D.empty ()
let threadenter ctx lval f args : D.t = D.empty ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v : D.t = D.empty ()

(* NB! Currently we care only about concrete indexes. Base (seeing only a int domain
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct

let startstate v = D.bot ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()
end

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/varEq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct

let startstate v = D.top ()
let threadenter ctx lval f args = D.top ()
let threadspawn ctx lval f args fctx = D.bot ()
let threadspawn ctx lval f args fctx = ctx.local
let exitstate v = D.top ()

let const_equal c1 c2 =
Expand Down
Loading

0 comments on commit 266da15

Please sign in to comment.