Skip to content

Commit ede09b8

Browse files
Merge pull request #1427 from goblint/issue_1379
Pass `ctx` to context & Simplify callstring-based approaches
2 parents bffc5e3 + 9084ba4 commit ede09b8

39 files changed

+206
-168
lines changed

src/analyses/abortUnless.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ struct
1313
module D = BoolDomain.MustBool
1414
module C = Printable.Unit
1515

16-
let context _ _ = ()
16+
let context ctx _ _ = ()
17+
let startcontext () = ()
1718

1819
(* transfer functions *)
1920
let assign ctx (lval:lval) (rval:exp) : D.t =

src/analyses/accessAnalysis.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct
1414
let name () = "access"
1515

1616
module D = Lattice.Unit
17-
module C = Printable.Unit
17+
include Analyses.ValueContexts(D)
1818

1919
module V =
2020
struct
@@ -52,11 +52,12 @@ struct
5252
);
5353
if M.tracing then M.traceu "access" "access_one_top"
5454

55+
5556
(** We just lift start state, global and dependency functions: *)
5657
let startstate v = ()
5758
let threadenter ctx ~multiple lval f args = [()]
5859
let exitstate v = ()
59-
let context fd d = ()
60+
let context ctx fd d = ()
6061

6162

6263
(** Transfer functions: *)

src/analyses/activeSetjmp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct
1010
let name () = "activeSetjmp"
1111

1212
module D = JmpBufDomain.JmpBufSet
13-
module C = JmpBufDomain.JmpBufSet
13+
include Analyses.ValueContexts(D)
1414
module P = IdentityP (D)
1515

1616
let combine_env ctx (lval:lval option) fexp (f:fundec) (args:exp list) fc (au:D.t) (f_ask:Queries.ask): D.t =

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct
2020
module Priv = Priv (RD)
2121
module D = RelationDomain.RelComponents (RD) (Priv.D)
2222
module G = Priv.G
23-
module C = D
23+
include Analyses.ValueContexts(D)
2424
module V =
2525
struct
2626
include Priv.V
@@ -40,7 +40,7 @@ struct
4040
(* Result map used for comparison of results for relational traces paper. *)
4141
let results = PCU.RH.create 103
4242

43-
let context fd x =
43+
let context ctx fd x =
4444
if ContextUtil.should_keep ~isAttr:GobContext ~keepOption:"ana.relation.context" ~removeAttr:"relation.no-context" ~keepAttr:"relation.context" fd then
4545
x
4646
else

src/analyses/base.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct
3838
module Dom = BaseDomain.DomFunctor (Priv.D) (RVEval)
3939
type t = Dom.t
4040
module D = Dom
41-
module C = Dom
41+
include Analyses.ValueContexts(D)
4242

4343
(* Two global invariants:
4444
1. Priv.V -> Priv.G -- used for Priv
@@ -79,6 +79,7 @@ struct
7979
type glob_diff = (V.t * G.t) list
8080

8181
let name () = "base"
82+
8283
let startstate v: store = { cpa = CPA.bot (); deps = Dep.bot (); weak = WeakUpdates.bot (); priv = Priv.startstate ()}
8384
let exitstate v: store = { cpa = CPA.bot (); deps = Dep.bot (); weak = WeakUpdates.bot (); priv = Priv.startstate ()}
8485

@@ -622,7 +623,7 @@ struct
622623

623624
let drop_intervalSet = CPA.map (function Int x -> Int (ID.no_intervalSet x) | x -> x )
624625

625-
let context (fd: fundec) (st: store): store =
626+
let context ctx (fd: fundec) (st: store): store =
626627
let f keep drop_fn (st: store) = if keep then st else { st with cpa = drop_fn st.cpa} in
627628
st |>
628629
(* Here earlyglobs only drops syntactic globals from the context and does not consider e.g. escaped globals. *)

src/analyses/callstring.ml

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(**
2-
Call String analysis [call_string] and/or Call Site analysis [call_site].
3-
The call string limitation for both approaches can be adjusted with the "callString_length" option.
4-
By adding new implementations of the CallstringType, additional analyses can be added.
2+
Call String analysis [call_string] and/or Call Site analysis [call_site].
3+
The call string limitation for both approaches can be adjusted with the "callString_length" option.
4+
By adding new implementations of the CallstringType, additional analyses can be added.
55
*)
66

77
open Analyses
@@ -18,20 +18,22 @@ end
1818

1919
(** Analysis with infinite call string or with limited call string (k-CFA, tracks the last k call stack elements).
2020
With the CT argument it is possible to specify the type of the call string elements *)
21-
module Spec (CT:CallstringType) : MCPSpec =
21+
module Spec (CT:CallstringType) : MCPSpec =
2222
struct
23-
include Analyses.IdentitySpec
23+
include UnitAnalysis.Spec
2424

2525
(* simulates a call string (with or without limitation)*)
2626
module CallString = struct
2727
include Printable.PQueue (CT)
2828

29+
let (empty:t) = BatDeque.empty
30+
2931
(* pushes "elem" to the call string, guarantees a depth of k if limitation is specified with "ana.context.callString_length" *)
30-
let push callstr elem =
32+
let push callstr elem =
3133
match elem with
3234
| None -> callstr
33-
| Some e ->
34-
let new_callstr = BatDeque.cons e callstr in (* pushes new element to callstr *)
35+
| Some e ->
36+
let new_callstr = BatDeque.cons e callstr in (* pushes new element to callstr *)
3537
if get_int "ana.context.callString_length" < 0
3638
then new_callstr (* infinite call string *)
3739
else (* maximum of k elements *)
@@ -41,46 +43,32 @@ struct
4143
| _ -> failwith "CallString Error: It shouldn't happen that more than one element must be deleted to maintain the correct height!"
4244
end
4345

44-
module D = Lattice.Flat (CallString) (* should be the CallString (C=D). Since a Lattice is required, Lattice.Flat is used to fulfill the type *)
4546
module C = CallString
46-
module V = EmptyV
47-
module G = Lattice.Unit
4847

4948
let name () = "call_"^ CT.ana_name
50-
let startstate v = `Lifted (BatDeque.empty)
51-
let exitstate v = `Lifted (BatDeque.empty)
52-
53-
let context fd x = match x with
54-
| `Lifted x -> x
55-
| _ -> failwith "CallString: Context error! The context cannot be derived from Top or Bottom!"
56-
57-
let callee_state ctx f =
58-
let elem = CT.new_ele f ctx in (* receive element that should be added to call string *)
59-
let new_callstr = CallString.push (context f ctx.local) elem in
60-
`Lifted new_callstr
61-
62-
let enter ctx r f args = [ctx.local, callee_state ctx f]
6349

64-
let combine_env ctx lval fexp f args fc au f_ask = ctx.local
50+
let startcontext () = CallString.empty
6551

66-
let threadenter ctx ~multiple lval v args = [callee_state ctx (Cilfacade.find_varinfo_fundec v)]
52+
let context ctx fd _ =
53+
let elem = CT.new_ele fd ctx in (* receive element that should be added to call string *)
54+
CallString.push (ctx.context ()) elem
6755
end
6856

6957
(* implementations of CallstringTypes*)
7058
module Callstring: CallstringType = struct
7159
include CilType.Fundec
7260
let ana_name = "string"
73-
let new_ele f ctx =
74-
let f' = Node.find_fundec ctx.node in
75-
if CilType.Fundec.equal f' dummyFunDec
61+
let new_ele f ctx =
62+
let f' = Node.find_fundec ctx.node in
63+
if CilType.Fundec.equal f' dummyFunDec
7664
then None
7765
else Some f'
7866
end
7967

8068
module Callsite: CallstringType = struct
8169
include CilType.Stmt
8270
let ana_name = "site"
83-
let new_ele f ctx =
71+
let new_ele f ctx =
8472
match ctx.prev_node with
8573
| Statement stmt -> Some stmt
8674
| _ -> None (* first statement is filtered *)

src/analyses/condVars.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct
5858

5959
let name () = "condvars"
6060
module D = Domain
61-
module C = Domain
61+
include Analyses.ValueContexts(D)
6262

6363
(* >? is >>=, |? is >> *)
6464
let (>?) = Option.bind

src/analyses/expsplit.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct
1313
let name () = "expsplit"
1414

1515
module D = MapDomain.MapBot (Basetype.CilExp) (ID)
16-
module C = D
16+
include Analyses.ValueContexts(D)
1717

1818
let startstate v = D.bot ()
1919
let exitstate = startstate

src/analyses/extractPthread.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ module Spec : Analyses.MCPSpec = struct
866866
(** Domains *)
867867
module D = PthreadDomain.D
868868

869-
module C = D
869+
include Analyses.ValueContexts(D)
870870

871871
(** Set of created tasks to spawn when going multithreaded *)
872872
module G = Tasks

src/analyses/locksetAnalysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct
1515
let name () = "lockset"
1616

1717
module D = D
18-
module C = D
18+
include Analyses.ValueContexts(D)
1919

2020
let startstate v = D.empty ()
2121
let threadenter ctx ~multiple lval f args = [D.empty ()]

0 commit comments

Comments
 (0)