Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master thesis: Taming Recursion with Three Context-Sensitive Analyses (Callstring, LoopfreeCallstring, Context Gas) #1340

Merged
merged 176 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 174 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
51b197f
added a new lifter in constraints, converted C to an option and tried…
Oct 19, 2023
163123f
added lifter to control, added context gas in lifter, with this chang…
Oct 19, 2023
e7610f3
Merge branch 'goblint:master' into master
SchiJoha Oct 22, 2023
7f6f3e0
changed constraints, added test case, not working if context gas = 0
Oct 22, 2023
8109fbb
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Oct 22, 2023
9347703
just checking if the tests in github actions are now working :)), not…
Oct 23, 2023
c861d29
added two testcases; fixed a copy paste error in query; deleted debug…
Nov 1, 2023
2334b73
Merge branch 'goblint:master' into master
SchiJoha Nov 1, 2023
badfe3b
removed prints for clean output
Nov 2, 2023
4b89cd1
status after the 2. meeting with supervisor
Nov 2, 2023
e5de165
changed module C, no compiler errors, but implementations are not com…
Nov 2, 2023
ac289ee
converted D to a Product with an Int, same for C, changed the transfe…
Nov 7, 2023
9d80e8f
Merge branch 'goblint:master' into master
SchiJoha Nov 7, 2023
4fdb9bc
moved int Printable and lattice to the corresponding file; added and…
Nov 7, 2023
aea2345
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Nov 7, 2023
6fb946b
adapted to changes from Master: added multiple
Nov 7, 2023
b72e941
fixed small error at enter transfer function; now decrement should wo…
Nov 9, 2023
85cf293
Merge branch 'goblint:master' into master
SchiJoha Nov 9, 2023
c346894
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Nov 9, 2023
fb5642f
test if not working github tests are due to longjmpLifter
Nov 9, 2023
faab50f
Longjump enabled, working
Nov 10, 2023
f5b5af1
moved contextGasLifter upwards, hopefully fixes some of the regressio…
Nov 13, 2023
47e7577
made context lifter optional; added option to test cases
Nov 14, 2023
9aa8a5e
adapted the hardcoded path in test-gobview to match with this reposit…
Nov 14, 2023
a9eaeb4
used Chain for ctxGasLifter (deleted Int module in Printable and Latt…
Nov 17, 2023
80eee49
fixed indentation, added kCallstring module, just a first draft
Nov 23, 2023
daac0cd
pulled Master, resolved merge conflict
Nov 23, 2023
df56220
added kCallstring to goblint_lib; fixed indentation
Nov 23, 2023
fe41d6b
fixed typo in file name; added new testcases; adapted existing ones
Nov 24, 2023
b82cd6b
Merge branch 'goblint:master' into master
SchiJoha Nov 24, 2023
432bd1e
deleted kCallstring, created new Callstring Lifter, added new testcas…
Nov 27, 2023
133fa2e
fixed a typo in a file name
Nov 27, 2023
416a100
merged master
Nov 27, 2023
3d6aba4
made the callstring approach modular (different types of callstack el…
Nov 27, 2023
14c2e58
deleted main tracking from Callstring lifter; added testcases
Nov 27, 2023
269b47a
added new testcases, a few explanations in constraints
Nov 28, 2023
960e009
Merge branch 'goblint:master' into master
SchiJoha Nov 29, 2023
ef3f21f
Merge branch 'goblint:master' into master
SchiJoha Dec 4, 2023
4bfbfac
moved callstring ana from lifter to analysis (must be tested), adapte…
Dec 4, 2023
0ebbbb3
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Dec 4, 2023
08ff7b5
Merge branch 'goblint:master' into master
SchiJoha Dec 5, 2023
578240e
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Dec 5, 2023
0b93041
Merge branch 'goblint:master' into master
SchiJoha Dec 5, 2023
bf50b02
used options.schema.json for variable storing; used different Lattice…
Dec 5, 2023
3c16ff3
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Dec 5, 2023
e88eccd
built right context for callstring analysis in mcp; deleted unnecessa…
Dec 5, 2023
1cdefeb
now also multiple calls are handled properly by the callstring Ana; a…
Dec 6, 2023
343f83d
2 lists for stack representation in callstring
Dec 6, 2023
0ad54b5
added location for callstack type, added queue impl in printable, add…
Dec 8, 2023
74610ab
implemented Queue completely, added new callstringAna for usage of qu…
Dec 8, 2023
0a99863
added a new lifter in constraints, converted C to an option and tried…
Oct 19, 2023
874e4d6
added lifter to control, added context gas in lifter, with this chang…
Oct 19, 2023
3e395ef
changed constraints, added test case, not working if context gas = 0
Oct 22, 2023
b917ec2
just checking if the tests in github actions are now working :)), not…
Oct 23, 2023
d6e0940
added two testcases; fixed a copy paste error in query; deleted debug…
Nov 1, 2023
bfb507d
removed prints for clean output
Nov 2, 2023
9958bf5
status after the 2. meeting with supervisor
Nov 2, 2023
d9211e1
changed module C, no compiler errors, but implementations are not com…
Nov 2, 2023
938a623
converted D to a Product with an Int, same for C, changed the transfe…
Nov 7, 2023
53bc11d
moved int Printable and lattice to the corresponding file; added and…
Nov 7, 2023
cb557c9
adapted to changes from Master: added multiple
Nov 7, 2023
7818511
fixed small error at enter transfer function; now decrement should wo…
Nov 9, 2023
a51a843
Longjump enabled, working
Nov 10, 2023
c035e3a
moved contextGasLifter upwards, hopefully fixes some of the regressio…
Nov 13, 2023
e83fa36
made context lifter optional; added option to test cases
Nov 14, 2023
49c5a57
adapted the hardcoded path in test-gobview to match with this reposit…
Nov 14, 2023
145f577
used Chain for ctxGasLifter (deleted Int module in Printable and Latt…
Nov 17, 2023
50d779e
fixed indentation, added kCallstring module, just a first draft
Nov 23, 2023
f0812d9
added kCallstring to goblint_lib; fixed indentation
Nov 23, 2023
5eb87d9
fixed typo in file name; added new testcases; adapted existing ones
Nov 24, 2023
75e1931
deleted kCallstring, created new Callstring Lifter, added new testcas…
Nov 27, 2023
f4b8457
fixed a typo in a file name
Nov 27, 2023
54a7798
made the callstring approach modular (different types of callstack el…
Nov 27, 2023
3b2a1d0
deleted main tracking from Callstring lifter; added testcases
Nov 27, 2023
0c21a3a
added new testcases, a few explanations in constraints
Nov 28, 2023
f29cfc5
moved callstring ana from lifter to analysis (must be tested), adapte…
Dec 4, 2023
ddd2070
used options.schema.json for variable storing; used different Lattice…
Dec 5, 2023
958b619
built right context for callstring analysis in mcp; deleted unnecessa…
Dec 5, 2023
8fbfe67
now also multiple calls are handled properly by the callstring Ana; a…
Dec 6, 2023
d0b6e83
2 lists for stack representation in callstring
Dec 6, 2023
5cc34a2
added location for callstack type, added queue impl in printable, add…
Dec 8, 2023
6743228
implemented Queue completely, added new callstringAna for usage of qu…
Dec 8, 2023
2acb942
adapted sv comp files for callstring and ctx gas; added queue impleme…
Dec 9, 2023
85a06d4
pulled from master and fixed merge conflicts; deleted gobview since m…
Dec 9, 2023
3f712b2
added gobview, changed Tracing to Goblint_tracing, added queue2L to g…
Dec 9, 2023
62a87a2
deleted unnecessary sv comp secification
Dec 9, 2023
e150463
removed print statements for sv comp run
Dec 10, 2023
30f636d
Merge branch 'goblint:master' into master
SchiJoha Dec 19, 2023
72c68c4
renamed Queue2L -> QueueImmut; made mcp implementation more efficient…
Dec 20, 2023
0554987
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Dec 20, 2023
6d214d1
Merge branch 'goblint:master' into master
SchiJoha Dec 21, 2023
b96a8cc
renamed CFName to NoContext, used stored context gas value for IntCon…
Jan 2, 2024
100fdca
merged master
Jan 2, 2024
3dbdad5
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Jan 2, 2024
161d2ff
disabled options in autotune which may caused failing sv-comps (big p…
Jan 4, 2024
3c4ff7d
updated gobview with master, correct condition for test
Jan 5, 2024
0d73e26
autotune: standard config, callstring: shortend code, added threadent…
Jan 9, 2024
49b244a
added callStack_height specification to callstring tests; added new s…
Jan 11, 2024
4904b05
Merge branch 'goblint:master' into master
SchiJoha Jan 11, 2024
d6bc63e
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Jan 11, 2024
834edd9
added widen context Lifter config
Jan 12, 2024
6459e02
added contextJoins, added testcases for contextJoins, added json for it
Jan 17, 2024
873605f
Merge branch 'goblint:master' into master
SchiJoha Jan 22, 2024
37150f6
renamed contextJoins to callstringTracking, improved implementation i…
Jan 23, 2024
136a6d2
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Jan 23, 2024
09cd487
Merge branch 'goblint:master' into master
SchiJoha Jan 23, 2024
7f5c856
pulled from master; fixed indentation; deleted print in mcp
Jan 23, 2024
bbe97b5
fixed error in relationAnalysis: assign in combine_env instead of sub…
Jan 25, 2024
b7a29f8
restored relationAnalysis (apron), disabled path sensitivity for call…
Jan 26, 2024
850e118
made everything ready for pull request: deleted prints, deleted unnec…
Jan 26, 2024
d87e541
renamed svcomp configuration
Jan 26, 2024
a3d019e
renamed svcomp configs; restore some entries in options.schema.json w…
Jan 26, 2024
2d6f0a3
Merge branch 'goblint:master' into master
SchiJoha Jan 26, 2024
15d4e8c
adapt indentation to master
Jan 26, 2024
ed4c7cc
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Jan 26, 2024
550bbbc
rephrased ctx_gas and callstack description
Jan 26, 2024
7a051d1
Merge branch 'goblint:master' into master
SchiJoha Jan 26, 2024
59f2258
fixed indentation to match master
Jan 26, 2024
f5205ef
Merge branch 'goblint:master' into master
SchiJoha Jan 30, 2024
8967b10
replaced queueImmut with BatDeque
Jan 30, 2024
5c8a860
renamed callstringTracking to loopfreeCallstring; loopfreeCallstring:…
Feb 4, 2024
ae643cd
callstringAnalysis: renamed pushElem to stackElem; inlined the depth …
Feb 4, 2024
db25e45
Merge branch 'goblint:master' into master
SchiJoha Feb 4, 2024
23b8b5b
fixed typo
Feb 4, 2024
7d1b6b2
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Feb 4, 2024
5516b77
deleted noRecursiveIntervals from context configurations
Feb 4, 2024
abecc7a
renamed repository and updated path in test-gobview to pass gobview test
Feb 4, 2024
f9e774a
fixed loopfreeCallstring configuration
Feb 5, 2024
b2f7543
uploaded list_search-1.i test: problems with soundness
Feb 5, 2024
465b5c1
fixed join error in apron domain: replaced is_bot with is_bot_env (ot…
Feb 6, 2024
899b67b
updated configurations for paper: renamed, deleted octagon in autotun…
Feb 6, 2024
e99d03e
renamed tests for loopfreeCallstring; small comments; reverted apronD…
Feb 6, 2024
6c5e2f6
callstack can be infinite
Feb 9, 2024
e92d803
added configs for inf callstack
Feb 9, 2024
b851ded
changed loopfreeCallstring analysis to have multiple lists and sets, …
Feb 11, 2024
3001590
Merge remote-tracking branch 'upstream/master'
Feb 11, 2024
a7bf70e
deleted context gas from C, is just tracked in ctx.local; updated tes…
Feb 11, 2024
6520557
updated testcases loopfreeCallstring + callstring fundec
Feb 12, 2024
9325303
disabled witness.yaml because join on loopfreeCallstring-stack is not…
Feb 19, 2024
76f8ce1
Merge branch 'goblint:master' into master
SchiJoha Feb 19, 2024
5309871
changed callstring stackheight to 2
Feb 19, 2024
0ee18f4
Merge branch 'goblint:master' into master
SchiJoha Feb 28, 2024
b51640d
Merge branch 'goblint:master' into master
SchiJoha Mar 6, 2024
832f83e
loopfree: list of elements -> elements; update comments of examples
Mar 7, 2024
12ae21e
update g2html and gobview with master
Mar 7, 2024
7582750
elegant solution for loopfree callstring
Mar 8, 2024
89926d5
updated g2html and gobview
Mar 8, 2024
b226413
inf callstack option is now negative callstack height; implemented re…
Mar 12, 2024
9853562
option to enable/disable is merged with context gas value: negative v…
Mar 12, 2024
08e1c73
updated comment of analysis in callstring; updated configs for sv comp
Mar 12, 2024
73f5a16
add marshal to context gas lifter
Mar 12, 2024
1649dca
add ana.ctx_sens option
Mar 13, 2024
1eb23c0
update comment of contextGasLifter
Mar 13, 2024
f677e76
Merge
Mar 13, 2024
3b9889c
new config file for master thesis -> moved all thesis related configs…
Mar 13, 2024
14a8fe9
enabled octagon autotuning and yaml for masterthesis configs
Mar 15, 2024
e9c3173
added context gas 0 config
Mar 15, 2024
a1f479e
Merge branch 'goblint:master' into master
SchiJoha Mar 17, 2024
710cd14
Merge branch 'goblint:master' into master
SchiJoha Mar 19, 2024
a9b03bb
add explanatory comments
Mar 20, 2024
ad98e86
Merge branch 'master' of https://github.com/SchiJoha/GobContextGas
Mar 20, 2024
96b47c5
merged, default call stack height is now 2
Apr 7, 2024
3b75f9e
add cont_sens_ids set to check for inse ana more efficiently
Apr 7, 2024
a88606e
deleted configurations, deleted call_string_withCallee, updated calls…
Apr 14, 2024
12fab36
update comments on constraints and loopfreeCallstring
Apr 15, 2024
52a507b
updated comments, updated tests
Apr 15, 2024
af12e58
commit to make the indentation test pass...
Apr 15, 2024
faebe6d
Merge remote-tracking branch 'upstream/master'
Apr 15, 2024
d6a390d
renumbered call string tests to 79; update comments of tests
Apr 15, 2024
67e2d8f
Merge branch 'goblint:master' into master
SchiJoha Apr 16, 2024
fa04a59
Merge branch 'goblint:master' into master
SchiJoha Apr 17, 2024
cefc1e2
update description: callString_length is only effective with activate…
Apr 17, 2024
97d5ad2
Formatting suggestion by Simmo
michael-schwarz Apr 18, 2024
9279abd
Merge branch 'goblint:master' into master
SchiJoha Apr 19, 2024
b7e60c4
Merge remote-tracking branch 'upstream/master'
Apr 22, 2024
c1165e1
cosmetic changes from Julian (on options, loopfree Callstring and cal…
Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gobview
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
Submodule gobview updated 0 files
94 changes: 94 additions & 0 deletions src/analyses/callstring.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
(**
Call String analysis [call_string] and/or Call Site analysis [call_site].
The call string limitation for both approaches can be adjusted with the "callString_length" option.
By adding new implementations of the CallstringType, additional analyses can be added.
*)

open Analyses
open GoblintCil
open GobConfig

(* Specifies the type of the call string elements *)
module type CallstringType =
sig
include CilType.S
val ana_name: string
val new_ele: fundec -> ('d,'g,'c,'v) ctx -> t option (* returns an element that should be pushed to the call string *)
end

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

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

(* pushes "elem" to the call string, guarantees a depth of k if limitation is specified with "ana.context.callString_length" *)
let push callstr elem =
match elem with
| None -> callstr
| Some e ->
let new_callstr = BatDeque.cons e callstr in (* pushes new element to callstr *)
if get_int "ana.context.callString_length" < 0
then new_callstr (* infinite call string *)
else (* maximum of k elements *)
match (BatDeque.size new_callstr - (get_int "ana.context.callString_length")) with
jerhard marked this conversation as resolved.
Show resolved Hide resolved
| 1 -> fst @@ Option.get (BatDeque.rear new_callstr)
| x when x <= 0 -> new_callstr
| _ -> failwith "CallString Error: It shouldn't happen that more than one element must be deleted to maintain the correct height!"
end

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

let name () = "call_"^ CT.ana_name
let startstate v = `Lifted (BatDeque.empty)
let exitstate v = `Lifted (BatDeque.empty)

let context fd x = match x with
| `Lifted x -> x
| _ -> failwith "CallString: Context error! The context cannot be derived from Top or Bottom!"

let callee_state ctx f =
let elem = CT.new_ele f ctx in (* receive element that should be added to call string *)
let new_callstr = CallString.push (context f ctx.local) elem in
`Lifted new_callstr

let enter ctx r f args = [ctx.local, callee_state ctx f]

let combine_env ctx lval fexp f args fc au f_ask = ctx.local

let threadenter ctx ~multiple lval v args = [callee_state ctx (Cilfacade.find_varinfo_fundec v)]
end

(* implementations of CallstringTypes*)
module Callstring:CallstringType = struct
include CilType.Fundec
let ana_name = "string"
let new_ele f ctx =
let f' = Node.find_fundec ctx.node in
if CilType.Fundec.equal f' dummyFunDec
then None
else Some f'
end

module Callsite:CallstringType = struct
jerhard marked this conversation as resolved.
Show resolved Hide resolved
include CilType.Stmt
let ana_name = "site"
let new_ele f ctx =
match ctx.prev_node with
| Statement stmt -> Some stmt
| _ -> None (* first statement is filtered *)
end

let _ =
(* call string approach *)
MCP.register_analysis (module Spec (Callstring) : MCPSpec); (* [call_string] *)

(* call site approach *)
MCP.register_analysis (module Spec (Callsite) : MCPSpec); (* [call_site] *)
60 changes: 60 additions & 0 deletions src/analyses/loopfreeCallstring.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(**
Loopfree Callstring analysis [loopfree_callstring] that reduces the call string length of the classical Call String approach for recursions
The idea is to improve the Call String analysis by representing all detected call cycle of the call string in a set
In case no call cycles appears, the call string is identical to the call string of the Call String approach
For example:
- call string [main, a, b, c, a] is represented as [main, {a, b, c}]
- call string [main, a, a, b, b, b] is represented as [main, {a}, {b}]

This approach is inspired by
@see <https://arxiv.org/abs/2301.06439> Schwarz, M., Saan, S., Seidl, H., Erhard, J., Vojdani, V. Clustered Relational Thread-Modular Abstract Interpretation with Local Traces. Appendix F.
*)
open Analyses

module Spec : MCPSpec =
struct
include Analyses.IdentitySpec

let name () = "loopfree_callstring"

module FundecSet = SetDomain.Make (CilType.Fundec)
module Either = Printable.Either (CilType.Fundec) (FundecSet)

module D = Lattice.Flat (Printable.Liszt (Either)) (* should be a List containing Sets of Fundecs and Fundecs. Lattice.Flat is used to fulfill the type *)
jerhard marked this conversation as resolved.
Show resolved Hide resolved
module C = D
module V = EmptyV
module G = Lattice.Unit
let startstate v = `Lifted([])
let exitstate v = `Lifted([])

let get_list list = match list with
| `Lifted e -> e
| _ -> failwith "Error loopfreeCallstring (get_list): The list cannot be derived from Top or Bottom!"

let loop_detected f = function
(* note: a call string contains each Fundec at most once *)
| `Left ele -> CilType.Fundec.equal f ele
| `Right set -> FundecSet.mem f set

let add_to_set old = function
| `Left ele -> FundecSet.add ele old
| `Right set -> FundecSet.join old set

let rec callee_state f prev_set prev_list = function
| [] -> (`Left f)::(List.rev prev_list) (* f is not yet contained in the call string *)
| e::rem_list ->
let new_set = add_to_set prev_set e in
if loop_detected f e (* f is already present in the call string *)
then (`Right new_set)::rem_list (* combine all elements of the call cycle in a set *)
else callee_state f new_set (e::prev_list) rem_list

let callee_state f ctx = `Lifted(callee_state f (FundecSet.empty ()) [] (get_list ctx.local))

let enter ctx r f args = [ctx.local, callee_state f ctx]

let threadenter ctx ~multiple lval v args = [callee_state (Cilfacade.find_varinfo_fundec v) ctx]

let combine_env ctx lval fexp f args fc au f_ask = ctx.local
end

let _ = MCP.register_analysis (module Spec : MCPSpec)
16 changes: 12 additions & 4 deletions src/analyses/mCP.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct
let name () = "MCP2"

let path_sens = ref []
let cont_inse = ref []
let act_cont_sens = ref Set.empty
let base_id = ref (-1)


Expand Down Expand Up @@ -80,10 +80,18 @@ struct
base_id := find_id "base";
activated := map (fun s -> s, find_spec s) xs;
path_sens := map' find_id @@ get_string_list "ana.path_sens";
cont_inse := map' find_id @@ get_string_list "ana.ctx_insens";
check_deps !activated;
activated := topo_sort_an !activated;
activated_ctx_sens := List.filter (fun (n, _) -> not (List.mem n !cont_inse)) !activated;
begin
match get_string_list "ana.ctx_sens" with
| [] -> (* use values of "ana.ctx_insens" (blacklist) *)
let cont_inse = map' find_id @@ get_string_list "ana.ctx_insens" in
activated_ctx_sens := List.filter (fun (n, _) -> not (List.mem n cont_inse)) !activated;
| sens -> (* use values of "ana.ctx_sens" (whitelist) *)
let cont_sens = map' find_id @@ sens in
activated_ctx_sens := List.filter (fun (n, _) -> List.mem n cont_sens) !activated;
end;
act_cont_sens := Set.of_list (List.map (fun (n,p) -> n) !activated_ctx_sens);
activated_path_sens := List.filter (fun (n, _) -> List.mem n !path_sens) !activated;
match marshal with
| Some marshal ->
Expand All @@ -108,7 +116,7 @@ struct
let context fd x =
let x = spec_list x in
filter_map (fun (n,(module S:MCPSpec),d) ->
if mem n !cont_inse then
if Set.is_empty !act_cont_sens || not (Set.mem n !act_cont_sens) then (*n is insensitive*)
None
else
Some (n, repr @@ S.context fd (obj d))
Expand Down
37 changes: 37 additions & 0 deletions src/common/domains/printable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,43 @@ module Prod4 (Base1: S) (Base2: S) (Base3: S) (Base4: S) = struct
let arbitrary () = QCheck.quad (Base1.arbitrary ()) (Base2.arbitrary ()) (Base3.arbitrary ()) (Base4.arbitrary ())
end

module PQueue (Base: S) =
struct
type t = Base.t BatDeque.dq
include Std

let show x = "[" ^ (BatDeque.fold_right (fun a acc -> Base.show a ^ ", " ^ acc) x "]")

let pretty () x = text (show x)
let name () = Base.name () ^ "queue"

let relift x = BatDeque.map Base.relift x

let printXml f xs =
let rec loop n q =
match BatDeque.front q with
| None -> ()
| Some (x, xs) -> (BatPrintf.fprintf f "<key>%d</key>\n%a\n" n Base.printXml x;
loop (n+1) (xs))
in
BatPrintf.fprintf f "<value>\n<map>\n";
loop 0 xs;
BatPrintf.fprintf f "</map>\n</value>\n"

let to_yojson q = `List (BatDeque.to_list @@ BatDeque.map (Base.to_yojson) q)
let hash q = BatDeque.fold_left (fun acc x -> (acc + 71) * (Base.hash x)) 11 q
let equal q1 q2 = BatDeque.eq ~eq:Base.equal q1 q2
let compare q1 q2 =
match BatDeque.front q1, BatDeque.front q2 with
| None, None -> 0
| None, Some(_, _) -> -1
| Some(_, _), None -> 1
| Some(a1, q1'), Some(a2, q2') ->
let c = Base.compare a1 a2 in
if c <> 0 then c
else compare q1' q2'
end

module Liszt (Base: S) =
struct
type t = Base.t list [@@deriving eq, ord, hash, to_yojson]
Expand Down
21 changes: 20 additions & 1 deletion src/config/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,18 @@
},
"ctx_insens": {
"title": "ana.ctx_insens",
"description": "List of context-insensitive analyses",
"description": "List of context-insensitive analyses, which is ignored if `ctx_sens` is not empty.",
jerhard marked this conversation as resolved.
Show resolved Hide resolved
"type": "array",
"items": { "type": "string" },
"default": [ "stack_loc", "stack_trace_set" ]
},
"ctx_sens": {
"title": "ana.ctx_sens",
"description": "List of context-sensitive analyses. In case of an empty array `ctx_insens` is used, otherwise `ctx_insens` is ignored.",
jerhard marked this conversation as resolved.
Show resolved Hide resolved
"type": "array",
"items": { "type": "string" },
"default": []
},
"setjmp" : {
"title": "ana.setjmp",
"description": "Setjmp/Longjmp analysis",
Expand Down Expand Up @@ -970,6 +977,18 @@
"Do widening on contexts. Keeps a map of function to call state; enter will then return the widened local state for recursive calls.",
"type": "boolean",
"default": false
},
"gas_value": {
"title": "ana.context.gas_value",
"description": "x denotes the gas value for the ContextGasLifter. Negative value means deactivated, zero means context-insensitve analysis. If enabled, the first x recursive calls of the call stack are analyzed context-sensitive, the remaining with no context.",
jerhard marked this conversation as resolved.
Show resolved Hide resolved
"type": "integer",
"default": -1
},
"callString_length": {
"title": "ana.context.callString_length",
"description": "Length of the call string that should be used as context for the call_string and/or call_site analyses. In case the value is zero, the analysis is context-insensitive. For a negative value, an infinite call string is used! For this option to be effective, one analysis of the `callstring.ml` file must be activated.",
jerhard marked this conversation as resolved.
Show resolved Hide resolved
"type": "integer",
"default": 2
}
},
"additionalProperties": false
Expand Down
85 changes: 85 additions & 0 deletions src/framework/constraints.ml
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,91 @@ struct
let event (ctx:(D.t,G.t,C.t,V.t) ctx) (e:Events.t) (octx:(D.t,G.t,C.t,V.t) ctx):D.t = lift_fun ctx D.lift S.event ((|>) (conv octx) % (|>) e) `Bot
end

module NoContext = struct let name = "no context" end
module IntConf =
struct
let n () = max_int
let names x = Format.asprintf "%d" x
end

(** Lifts a [Spec] with the context gas variable. The gas variable limits the number of context-sensitively analyzed function calls in a call stack.
For every function call the gas is reduced. If the gas is zero, the remaining function calls are analyzed without context-information *)
module ContextGasLifter (S:Spec)
sim642 marked this conversation as resolved.
Show resolved Hide resolved
: Spec with module D = Lattice.Prod (S.D) (Lattice.Chain (IntConf))
and module C = Printable.Option (S.C) (NoContext)
and module G = S.G
=
struct
include S

module Context_Gas_Prod (Base1: Lattice.S) (Base2: Lattice.S) =
struct
include Lattice.Prod (Base1) (Base2)
let printXml f (x,y) =
BatPrintf.fprintf f "<value>\n<map>\n<key>\n%s\n</key>\n%a<key>\nContext Gas Value\n</key>\n%a</map>\n</value>\n" (XmlUtil.escape (Base1.name ())) Base1.printXml x Base2.printXml y
end
module D = Context_Gas_Prod (S.D) (Lattice.Chain (IntConf)) (* Product of S.D and an integer, tracking the context gas value *)
module C = Printable.Option (S.C) (NoContext)
module G = S.G
module V = S.V
module P =
struct
include S.P
let of_elt (x, _) = of_elt x
end

(* returns context gas value of the given ctx *)
let cg_val ctx = snd ctx.local

type marshal = S.marshal
let init = S.init
let finalize = S.finalize

let name () = S.name ()^" with context gas"
let startstate v = S.startstate v, get_int "ana.context.gas_value"
let exitstate v = S.exitstate v, get_int "ana.context.gas_value"
let morphstate v (d,i) = S.morphstate v d, i

let context fd (d,i) =
(* only keep context if the context gas is greater zero *)
if i <= 0 then None else Some (S.context fd d)

let conv (ctx:(D.t,G.t,C.t,V.t) ctx): (S.D.t,G.t,S.C.t,V.t)ctx =
if (cg_val ctx <= 0)
then {ctx with local = fst ctx.local
; split = (fun d es -> ctx.split (d, cg_val ctx) es)
; context = (fun () -> ctx_failwith "no context (contextGas = 0)")}
else {ctx with local = fst ctx.local
; split = (fun d es -> ctx.split (d, cg_val ctx) es)
; context = (fun () -> Option.get (ctx.context ()))}

let enter ctx r f args =
(* callee gas = caller gas - 1 *)
let liftmap_tup = List.map (fun (x,y) -> (x, cg_val ctx), (y, max 0 (cg_val ctx - 1))) in
liftmap_tup (S.enter (conv ctx) r f args)

let threadenter ctx ~multiple lval f args =
let liftmap f = List.map (fun (x) -> (x, max 0 (cg_val ctx - 1))) f in
liftmap (S.threadenter (conv ctx) ~multiple lval f args)
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved

let sync ctx reason = S.sync (conv ctx) reason, cg_val ctx
let query ctx q = S.query (conv ctx) q
let assign ctx lval expr = S.assign (conv ctx) lval expr, cg_val ctx
let vdecl ctx v = S.vdecl (conv ctx) v, cg_val ctx
let body ctx fundec = S.body (conv ctx) fundec, cg_val ctx
let branch ctx e tv = S.branch (conv ctx) e tv, cg_val ctx
let return ctx r f = S.return (conv ctx) r f, cg_val ctx
let asm ctx = S.asm (conv ctx), cg_val ctx
let skip ctx = S.skip (conv ctx), cg_val ctx
let special ctx r f args = S.special (conv ctx) r f args, cg_val ctx
let combine_env ctx r fe f args fc es f_ask = S.combine_env (conv ctx) r fe f args (Option.bind fc Fun.id) (fst es) f_ask, cg_val ctx
let combine_assign ctx r fe f args fc es f_ask = S.combine_assign (conv ctx) r fe f args (Option.bind fc Fun.id) (fst es) f_ask, cg_val ctx
let paths_as_set ctx = List.map (fun (x) -> (x, cg_val ctx)) @@ S.paths_as_set (conv ctx)
let threadspawn ctx ~multiple lval f args fctx = S.threadspawn (conv ctx) ~multiple lval f args (conv fctx), cg_val ctx
let event ctx e octx = S.event (conv ctx) e (conv octx), cg_val ctx
end


module type Increment =
sig
val increment: increment_data option
Expand Down
1 change: 1 addition & 0 deletions src/framework/control.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let spec_module: (module Spec) Lazy.t = lazy (
let module S1 =
(val
(module MCP.MCP2 : Spec)
|> lift (get_int "ana.context.gas_value" >= 0) (module ContextGasLifter)
|> lift true (module WidenContextLifterSide) (* option checked in functor *)
(* hashcons before witness to reduce duplicates, because witness re-uses contexts in domain and requires tag for PathSensitive3 *)
|> lift (get_bool "ana.opt.hashcons" || arg_enabled) (module HashconsContextLifter)
Expand Down
2 changes: 2 additions & 0 deletions src/goblint_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ module UnitAnalysis = UnitAnalysis

module Assert = Assert
module LoopTermination = LoopTermination
module Callstring = Callstring
module LoopfreeCallstring = LoopfreeCallstring
module Uninit = Uninit
module Expsplit = Expsplit
module StackTrace = StackTrace
Expand Down
Loading
Loading