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

Unassume witness invariants during solving #796

Merged
merged 141 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
4cdb4bd
Hack apron unassume
sim642 Jul 25, 2022
b151c62
Use event to trigger unassume after each incoming edge
sim642 Jul 26, 2022
692eb84
Add MyCFG.current_cfg
sim642 Jul 26, 2022
48503c6
Add unassume analysis to read YAML witnesses
sim642 Jul 26, 2022
175cd53
Unassume witness invariants in apron analysis
sim642 Jul 26, 2022
99d51b4
Clean up unassume in Apron
sim642 Jul 26, 2022
f0f5d4d
Show warnings from Spec init
sim642 Jul 26, 2022
f6e6dd2
Forbid globals in Apron unassume
sim642 Jul 26, 2022
5d16198
Unassume witness invariants in base analysis
sim642 Jul 26, 2022
b53f9e6
Consider static in scope check
sim642 Jul 26, 2022
752f88a
Add witness unassume testing to update_suite.rb
sim642 Jul 26, 2022
94dadc2
Ignore unassumes with globals, exclude untracked in Apron
sim642 Jul 26, 2022
b5cb10e
Remove witness.yml files from update_suite.rb
sim642 Jul 26, 2022
10c28a0
Add info about unassuming
sim642 Jul 26, 2022
4c8a737
Emit Unassume from other transfer functions
sim642 Jul 27, 2022
e674f4f
Add preconditioned invariant unassuming
sim642 Jul 27, 2022
2b48d41
Fix precondition CIL parse errors in witness validation
sim642 Jul 27, 2022
557e12f
Replace unassume pre_invs assoc list with Hashtbl
sim642 Jul 27, 2022
b252258
Add script for checking evals count changes in regression tests with …
sim642 Jul 27, 2022
b1eb2eb
Fix update_suite.rb -w not checking anything
sim642 Jul 28, 2022
1007f57
Hack base unassume to not lose precision on non-first vars
sim642 Jul 28, 2022
a96aa0a
Add witness test for problematic base unassume invariant queries
sim642 Aug 8, 2022
048318b
Change base unassume invariant to delegate safe queries outside
sim642 Aug 8, 2022
e8bb6a2
Merge branch 'master' into yaml-witness-unassume
sim642 Aug 22, 2022
e4b5d9f
Make logical operator invariant result more precise
sim642 Aug 22, 2022
82e0e31
Add some TODO base unassume tests
sim642 Aug 30, 2022
df5030b
Extract base invariant to BaseInvariant module
sim642 Aug 31, 2022
342c23f
Fix witness invariant lines in tauto and contra tests
sim642 Aug 31, 2022
2bef780
Hack BaseInvariant for base unassume
sim642 Aug 31, 2022
8f2ed73
Use fixpoint for base unassume
sim642 Aug 31, 2022
5fd25c9
Add narrowing to base unassume
sim642 Aug 31, 2022
b00b2de
Move base unassume soundness join into fixpoint function
sim642 Sep 1, 2022
ed336aa
Extract LocalFixpoint module
sim642 Sep 1, 2022
be4a495
Use empty environment in base unassume
sim642 Sep 1, 2022
2d8c4f3
Add base unassume test with dereferenced invariant
sim642 Sep 1, 2022
0c307d1
Fix evals in base unassume mistakenly being used by refines
sim642 Sep 1, 2022
2983887
Fix base unassume with multiple same dereferenced variables in same i…
sim642 Sep 1, 2022
60f2485
Fix 36-apron/38-branch-global being too trivial
sim642 Sep 13, 2022
d6a6786
Add strengthening unassume example from paper
sim642 Sep 13, 2022
bb3e9f1
Implement strengthening unassume in apron
sim642 Sep 13, 2022
e534700
Add single-threaded apron global unassume test
sim642 Sep 14, 2022
d9c9b0d
Implement apron global unassume
sim642 Sep 14, 2022
6f89ebb
Add multi-threaded apron global unassume test
sim642 Sep 14, 2022
3cec958
Fix apron unassumed invariant info with globals
sim642 Sep 14, 2022
b132b67
Merge branch 'yaml-witness-unassume-base-empty-env' into yaml-witness…
sim642 Sep 14, 2022
d2da3e1
Allow globals in base unassume, force single-threaded mode for sets
sim642 Sep 14, 2022
b910b27
Remove side effects from base priv invariant write_global-s
sim642 Sep 13, 2022
3815cc1
Optimize and document base priv invariant write W
sim642 Sep 14, 2022
f01a9d2
Add multi-threaded base global unassume test
sim642 Sep 14, 2022
8a6b50b
Fix protection-based base priv V tracing
sim642 Sep 14, 2022
f5c44ff
Implement base global unassume
sim642 Sep 14, 2022
4517c1e
Add hacky widening tokens for unassume
sim642 Sep 14, 2022
a5ee11f
Add test for widening tokens on globals
sim642 Sep 15, 2022
415adf0
Add hacky widening tokens for base unassume globals
sim642 Sep 15, 2022
6a85ab1
Make local widening tokens reuse explicitly controlled
sim642 Sep 15, 2022
53adb3e
Fix octx' in MCP do_emits using wrong local
sim642 Sep 15, 2022
df6218f
Fix normal emits not run on splits
sim642 Sep 15, 2022
42c06d0
Use YAML witness entry UUIDs as widening tokens
sim642 Sep 15, 2022
cd6c9d2
Add widening tokens to apron unassume
sim642 Sep 15, 2022
d848519
Extract widening token domain functor, add leq
sim642 Sep 15, 2022
e4ec677
Merge branch 'master' into yaml-witness-unassume
sim642 Oct 4, 2022
5b16195
Fix BaseInvariant indentation
sim642 Oct 4, 2022
776c1f2
Add YAML unassume testing on SV-COMP
sim642 Sep 16, 2022
7283b35
Add option witness.invariant.exact
sim642 Sep 16, 2022
6655115
Disable GraphML witnesses in svcomp-yaml confs
sim642 Sep 16, 2022
a32bf8f
Filter unassume nodes according to options
sim642 Sep 16, 2022
8a5c099
Emit inexact invariants for top intervals
sim642 Sep 16, 2022
392b32c
Optimize base unassume queries with cache
sim642 Sep 16, 2022
a99b51d
Benchmark Zarith power of 2
sim642 Sep 16, 2022
b82d356
Optimize LocalFixpoint with narrowing reuse
sim642 Sep 16, 2022
79f7771
Add TODO about widening token domain equal
sim642 Sep 19, 2022
3a2ee42
Enable Stats call counting
sim642 Sep 19, 2022
c43cb80
Implement var_eq unassume to fix SV-COMP unassuming
sim642 Sep 19, 2022
f2622ef
Increase Yaml.to_string buffer size for long SV-COMP task names
sim642 Sep 19, 2022
9aa4281
Add data to typeOfError-s
sim642 Sep 19, 2022
73df4ca
Fix YAML witness precondition invariant TypeOfError-s
sim642 Sep 19, 2022
672d8a4
Add eloc fallback to loc
sim642 Sep 19, 2022
baf2497
Handle witness.invariant.exact in base address sets
sim642 Sep 19, 2022
a9a6a7a
Add regexes for filtering invariant variable names
sim642 Sep 19, 2022
c01a7a3
Fix unassume causing more evals on sv-benchmarks/c/loops-crafted-1/ne…
sim642 Sep 19, 2022
3375949
Add additional LDV invariant variable filters
sim642 Sep 20, 2022
d8ee00f
Add option witness.invariant.exclude-vars
sim642 Sep 20, 2022
922e91f
Emit def_exc range invariant if more precise than ikind range
sim642 Sep 20, 2022
7c3070a
Add bench-yaml confs
sim642 Sep 27, 2022
ca9db19
Optimize unassume to not emit during postsolving
sim642 Sep 27, 2022
3e11774
Fix widening tokens domain identity causing extra work
sim642 Sep 27, 2022
e5855ba
Fix BenchZarith indentation
sim642 Oct 4, 2022
b8716cd
Fix 56-witness/23-base-unassume-priv2 by reverting widening token lif…
sim642 Oct 4, 2022
9313c22
Fix YAML witness accessed lvals crash on sv-benchmarks/c/loops/bubble…
sim642 Oct 4, 2022
6c9a64a
Update YAML witness SV-COMP script
sim642 Oct 4, 2022
6c138dc
Clean up and document WideningTokens
sim642 Oct 4, 2022
b5de6e6
Fix test ID conflict 56/19
sim642 Oct 4, 2022
de6c681
Add option ana.widen.tokens
sim642 Oct 4, 2022
964bb7a
Fix 56-witness/12-apron-unassume-branch
sim642 Oct 4, 2022
1ea5997
Support witness.invariant.exact in apron
sim642 Oct 4, 2022
14d8320
Add option ana.base.invariant.unassume
sim642 Oct 5, 2022
6f31a88
Add option witness.invariant.inexact-type-bounds
sim642 Oct 5, 2022
e4a316a
Add option witness.yaml.entry-types
sim642 Oct 5, 2022
ce82c41
Make YAML witness generation context joining lazy
sim642 Oct 5, 2022
96db5d4
Merge branch 'master' into yaml-witness-unassume
sim642 Oct 7, 2022
1e981de
Remove temporary YAML BenchExec def
sim642 Oct 7, 2022
9426848
Fix 56-witness/10-apron-unassume-interval to not succeed because of o…
sim642 Oct 7, 2022
fa651e3
Fix base invariant not excluding interval bounds
sim642 Oct 7, 2022
73124ac
Add Miné tutorial examples for unassume
sim642 Oct 7, 2022
f3ff649
Add inc-dec unassume example from thread-witnesses
sim642 Oct 7, 2022
15e7a7e
Fix BaseInvariant indentation
sim642 Oct 7, 2022
d4687e4
Add unassume expression example from thread-witnesses
sim642 Oct 7, 2022
a816bb1
Refine by equality disjunction in base
sim642 Oct 7, 2022
bf25ca3
Refine addresses in base
sim642 Oct 7, 2022
8b307fe
Fix unassume inc-dec example on lockset-based privatizations
sim642 Oct 10, 2022
3ea59f7
Add option solvers.td3.remove-wpoint
sim642 Oct 12, 2022
20763b0
Add Halbwachs-Henry unassume examples
sim642 Oct 12, 2022
811f2af
Add Boutonnet-Halbwachs unassume examples
sim642 Oct 12, 2022
4b04fa1
Add Amato-Scozzari unassume example
sim642 Oct 12, 2022
b130b37
Merge branch 'master' into yaml-witness-unassume
sim642 Oct 25, 2022
26560c2
Deduplicate BaseInvariant refine_lv_fallback
sim642 Nov 8, 2022
f114a1f
Extract eval_rv_base_lval in base
sim642 Nov 8, 2022
312b8b4
Deduplicate BaseInvariant refine_lv
sim642 Nov 8, 2022
8915b01
Fix unconditional tracing in BaseInvariant
sim642 Nov 8, 2022
bc11ca7
Merge branch 'master' into yaml-witness-unassume
sim642 Nov 8, 2022
b1e0851
Unskip 56-witness/14-base-unassume-precondition
sim642 Nov 8, 2022
ceb280f
Merge branch 'yaml-witness-location' into yaml-witness-unassume-location
sim642 Nov 17, 2022
799cbd5
Support location_invariant in unassume
sim642 Nov 17, 2022
b96c0b2
Merge branch 'master' into yaml-witness-unassume
sim642 Dec 2, 2022
66b5b23
Add longer unassume analysis description
sim642 Dec 19, 2022
1631657
Add longer BenchZarith description
sim642 Dec 19, 2022
419fcec
Add WitnessUtil.Locator.clear
sim642 Dec 19, 2022
9109e44
Improve LocalFixpoint description
sim642 Dec 19, 2022
ed06c34
Merge branch 'master' into yaml-witness-unassume
sim642 Dec 19, 2022
cedb278
Update svcomp-yaml confs to svcomp conf, except autotune
sim642 Dec 22, 2022
abc47e6
Refactor YAML witness SV-COMP testing to use multiple run definitions
sim642 Dec 22, 2022
604b05c
Limit YAML witness SV-COMP testing to true verdicts
sim642 Dec 22, 2022
8ae3307
Fix YAML witness generation crash on preprocessed file
sim642 Dec 27, 2022
baa5b2d
Fix mutex analysis postsolving crash on smtprc_comb.c
sim642 Dec 27, 2022
4b6c4f2
Fix fixpoint error on thread creation wrapper with local access colle…
sim642 Dec 27, 2022
d19117e
Revert "Fix mutex analysis postsolving crash on smtprc_comb.c"
sim642 Dec 27, 2022
be4a51f
Add BenchExec for goblint-bench pthread programs with YAML witnesses
sim642 Dec 27, 2022
926bd9f
Make summary message totals distinct for grepping
sim642 Dec 27, 2022
da509ad
Update BenchExec YAML witness entries column regexes
sim642 Dec 27, 2022
b6f82c9
Add live lines columns to YAML witness BenchExec
sim642 Dec 27, 2022
6e76ea6
Promote total changes to cram tests
sim642 Dec 27, 2022
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
42 changes: 42 additions & 0 deletions scripts/suite-result-witness-evals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python3

# checks evals count changes after ./scripts/update_suite.rb -w


from pathlib import Path
import re


suite_result_path = Path("./tests/suite_result")

def extract_evals(path):
with path.open() as f:
s = f.read()
m = re.search(r"evals = (\d+)", s)
if m is not None:
return int(m.group(1))
else:
return None

count_same = 0
count_better = 0
count_worse = 0

for after_path in suite_result_path.glob("*/*.warn.txt2"):
before_path = after_path.with_suffix(".txt")
print(after_path, end=" ")
before_evals = extract_evals(before_path)
after_evals = extract_evals(after_path)
print(before_evals, after_evals)
if before_evals is not None and after_evals is not None:
if before_evals == after_evals:
count_same += 1
elif before_evals > after_evals:
count_better += 1
else:
count_worse += 1
print(f"WORSE! by {after_evals - before_evals}")

print(f"same: {count_same}")
print(f"better: {count_better}")
print(f"worse: {count_worse}")
22 changes: 21 additions & 1 deletion scripts/update_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def clearline
$dump = ARGV.last == "-d" && ARGV.pop
sequential = ARGV.last == "-s" && ARGV.pop
marshal = ARGV.last == "-m" && ARGV.pop
witness = ARGV.last == "-w" && ARGV.pop
incremental = ARGV.last == "-i" && ARGV.pop
report = ARGV.last == "-r" && ARGV.pop
only = ARGV[0] unless ARGV[0].nil?
if marshal || incremental then
if marshal || witness || incremental then
sequential = true
end
if marshal && incremental then
Expand Down Expand Up @@ -481,6 +482,23 @@ def run ()
end
end

class ProjectWitness < Project
def create_test_set(lines)
super(lines)
@testset.p = self
end
def run ()
filename = File.basename(@path)
cmd1 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile}0 --enable dbg.debug --set printstats true --enable witness.yaml.enabled --set goblint-dir .goblint-#{@id.sub('/','-')}-witness1 2>#{@testset.statsfile}0"
cmd2 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set ana.activated[+] unassume --enable dbg.debug --set printstats true --set witness.yaml.unassume witness.yml --set goblint-dir .goblint-#{@id.sub('/','-')}-witness2 2>#{@testset.statsfile}"
starttime = Time.now
run_testset(@testset, cmd1, starttime)
starttime = Time.now
run_testset(@testset, cmd2, starttime)
FileUtils.rm_f('witness.yml')
end
end

#processing the file information
projects = []
project_ids = Set.new
Expand Down Expand Up @@ -528,6 +546,8 @@ def run ()
ProjectIncr.new(id, testname, groupname, path, params, patch_path, conf_path)
elsif marshal then
ProjectMarshal.new(id, testname, groupname, path, params)
elsif witness then
ProjectWitness.new(id, testname, groupname, path, params)
else
Project.new(id, testname, groupname, path, params)
end
Expand Down
16 changes: 16 additions & 0 deletions src/analyses/apron/apronAnalysis.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ struct
Priv.enter_multithreaded (Analyses.ask_of_ctx ctx) ctx.global ctx.sideg st
| Events.Escape escaped ->
Priv.escape ctx.node (Analyses.ask_of_ctx ctx) ctx.global ctx.sideg st escaped
| Events.Unassume e ->
let apr = AD.bot () in (* empty env *)
(* add only relevant vars to env *)
let vars = Basetype.CilExp.get_vars e |> List.unique ~eq:CilType.Varinfo.equal |> List.filter AD.varinfo_tracked in
if List.for_all (fun v -> not v.vglob) vars then (
let apr = AD.add_vars apr (List.map V.local vars) in
let apr = List.fold_left assert_type_bounds apr vars in (* add type bounds to avoid overflow in top state *)
let apr = AD.assert_inv apr e false in
let apr' = AD.join ctx.local.apr apr in
M.info ~category:Witness "apron unassumed invariant: %a" d_exp e;
{ctx.local with apr = apr'}
)
else (
M.info ~category:Witness "apron didn't unassume invariant: %a" d_exp e;
ctx.local (* TODO: support unassume with globals *)
)
| _ ->
st

Expand Down
59 changes: 57 additions & 2 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,11 @@ struct
if M.tracing then M.tracel "inv" "Unhandled operator %a\n" d_binop op;
(* Be careful: inv_exp performs a meet on both arguments of the BOr / BXor. *)
a, b
| LAnd ->
if ID.to_bool c = Some true then
meet_bin c c
else
a, b
| op ->
if M.tracing then M.tracel "inv" "Unhandled operator %a\n" d_binop op;
a, b
Expand Down Expand Up @@ -1805,7 +1810,7 @@ struct
| `Int a, `Int b ->
let ikind = Cilfacade.get_ikind_exp e1 in (* both operands have the same type (except for Shiftlt, Shiftrt)! *)
let a', b' = inv_bin_int (a, b) ikind c op in
if M.tracing then M.tracel "inv" "binop: %a, a': %a, b': %a\n" d_exp e ID.pretty a' ID.pretty b';
if M.tracing then M.tracel "inv" "binop: %a, c: %a, a': %a, b': %a\n" d_exp e ID.pretty c ID.pretty a' ID.pretty b';
let st' = inv_exp a' e1 st in
let st'' = inv_exp b' e2 st' in
st''
Expand All @@ -1829,7 +1834,9 @@ struct
if is_some_bot v then raise Deadcode
else (
if M.tracing then M.tracel "inv" "improve variable %a from %a to %a (c = %a, c' = %a)\n" d_varinfo var VD.pretty oldv VD.pretty v ID.pretty c VD.pretty c';
set' (Var var,NoOffset) v st
let r = set' (Var var,NoOffset) v st in
if M.tracing then M.tracel "inv" "st from %a to %a\n" D.pretty st D.pretty r;
r
)
| Mem _, _ ->
(* For accesses via pointers, not yet *)
Expand Down Expand Up @@ -2569,6 +2576,52 @@ struct
(* D.join ctx.local @@ *)
ctx.local

let unassume (ctx: (D.t, _, _, _) ctx) e =
let e_cpa = CPA.bot () in
let vars = Basetype.CilExp.get_vars e |> List.unique ~eq:CilType.Varinfo.equal in
if List.for_all (fun v -> not v.vglob) vars then (
let e_cpa = List.fold_left (fun e_cpa v ->
CPA.add v (VD.top_value v.vtype) e_cpa
) e_cpa vars
in
(* TODO: structural unassume instead of invariant hack *)
let e_d =
(* The usual recursion trick for ctx. *)
(* Must change ctx used by ask to also use new st (not ctx.local), otherwise recursive EvalInt queries use outdated state. *)
(* Note: query is just called on base, but not any other analyses. Potentially imprecise, but seems to be sufficient for now. *)
let local: D.t = {ctx.local with cpa = e_cpa} in
let rec ctx' asked =
{ ctx with
ask = (fun (type a) (q: a Queries.t) -> query' asked q)
; local
}
and query': type a. Queries.Set.t -> a Queries.t -> a Queries.result = fun asked q ->
let anyq = Queries.Any q in
if Queries.Set.mem anyq asked then
Queries.Result.top q (* query cycle *)
else (
let asked' = Queries.Set.add anyq asked in
match q with
| MayEscape _ -> false (* HACK: avoids get_var in inv_exp thinking non-first var is global *)
michael-schwarz marked this conversation as resolved.
Show resolved Hide resolved
| _ ->
query (ctx' asked') q
)
in
let ctx = ctx' Queries.Set.empty in
if M.tracing then M.traceli "unassume" "base unassuming\n";
let r = invariant ctx (Analyses.ask_of_ctx ctx) ctx.global ctx.local e true in
if M.tracing then M.traceu "unassume" "base unassumed\n";
r
in
M.info ~category:Witness "base unassumed invariant: %a" d_exp e;
M.debug ~category:Witness "base unassumed state: %a" D.pretty e_d;
D.join ctx.local e_d
)
else (
M.info ~category:Witness "base didn't unassume invariant: %a" d_exp e;
ctx.local (* TODO: support unassume with globals *)
)

let event ctx e octx =
let st: store = ctx.local in
match e with
Expand All @@ -2586,6 +2639,8 @@ struct
| Events.AssignSpawnedThread (lval, tid) ->
(* TODO: is this type right? *)
set ~ctx (Analyses.ask_of_ctx ctx) ctx.global ctx.local (eval_lv (Analyses.ask_of_ctx ctx) ctx.global ctx.local lval) (Cilfacade.typeOfLval lval) (`Thread (ValueDomain.Threads.singleton tid))
| Events.Unassume e ->
unassume ctx e
| _ ->
ctx.local
end
Expand Down
Loading