Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a4ee518
Add yaml witness entries with context precondition
sim642 May 31, 2022
7dd2066
Add prototype for precondition invariant validation
sim642 May 31, 2022
42a9465
Add OCaml types for yaml witness entries
sim642 Jun 2, 2022
24db283
Add of_yaml to yaml witness types
sim642 Jun 2, 2022
548575f
Refactor yaml witness entry handling
sim642 Jun 2, 2022
792b8df
Add precondition_loop_invariant_certificate
sim642 Jun 2, 2022
193ef7b
Extract invariant parsing to WitnessUtil
sim642 Jun 6, 2022
f66ac5c
Extract node locating to WitnessUtil
sim642 Jun 6, 2022
d1afe27
Refactor yaml witness validation
sim642 Jun 6, 2022
03cbf6f
Change unknown precondition to be excluded from validation
sim642 Jun 6, 2022
d45d471
Add option_map and list_map combinators for GobYaml
sim642 Jun 6, 2022
a46a6bb
Use GobYaml.list in witness validation
sim642 Jun 6, 2022
553f2cd
Merge branch 'master' into yaml-witness-precondition
sim642 Jun 13, 2022
e779f93
Merge branch 'master' into yaml-witness-precondition
sim642 Jun 17, 2022
f58c4ec
Add example where the generated witnesses are unsound.
jerhard Jul 14, 2022
2114d85
Extract common function for creating contexts
jerhard Jul 18, 2022
4b85cca
Extract check whether node is Statement out of node_context
jerhard Jul 18, 2022
1c23167
Collect contexts that may satiesfy context invariants
jerhard Jul 18, 2022
0b7dca4
PreconditionInvariants: Create postcondition as disjunction of matchi…
jerhard Jul 18, 2022
e109d60
Fix indentation
jerhard Jul 18, 2022
8240a09
Fix comments
jerhard Jul 18, 2022
e4fb856
Precondition invariants: Handle case when invariant cannot be generat…
jerhard Jul 18, 2022
13dbcc3
Add missing word in comment
jerhard Jul 19, 2022
470c126
Fix comments and indentation
jerhard Jul 19, 2022
dc260c0
Use start state instead of context for generating preconditions
jerhard Jul 22, 2022
dd244a5
Merge branch 'master' into yaml-witness-precondition
sim642 Jul 25, 2022
4f5ba97
Remove commented-out yaml witness code
sim642 Jul 25, 2022
2b6abe4
Merge branch 'yaml-witness-precondition' into yaml-witness-preconditi…
sim642 Jul 25, 2022
da65728
Move ask_local_node into YamlWitness.Query
sim642 Jul 25, 2022
948cd31
Prefer ask_local over ask_local_node in YamlWitness
sim642 Jul 25, 2022
b50801e
Explicitely use BatHashtbl instead of doing it via Prelude.Hashtbl.
jerhard Jul 26, 2022
8f4cffc
Move comment about why we do not generate invariants for FunctionEntr…
jerhard Jul 26, 2022
b5ce4ba
Add comment to use IterSysVars when #391 (interactive) is merged
jerhard Jul 27, 2022
c1e9359
Check whether current_c.invariant can be generated before iterating o…
jerhard Jul 27, 2022
9e07541
Merge pull request #786 from goblint/yaml-witness-precondition-groups
sim642 Aug 4, 2022
d686533
Merge branch 'master' into yaml-witness-precondition
sim642 Aug 4, 2022
f9b85a1
Add YAML witnesses to .gitignore
sim642 Aug 4, 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ dune-workspace
# gobview
run/
gobview_out/*

# witnesses
witness.yml
witness.certificate.yml
8 changes: 8 additions & 0 deletions src/util/gobList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ let rec for_all3 f l1 l2 l3 = match l1, l2, l3 with
| x1 :: l1, x2 :: l2, x3 :: l3 -> f x1 x2 x3 && (for_all3 [@tailcall]) f l1 l2 l3
| _, _, _ -> invalid_arg "GobList.for_all3"

let rec fold_while_some (f : 'a -> 'b -> 'a option) (acc: 'a) (xs: 'b list): 'a option = match xs with
| [] -> Some acc
| x::xs ->
begin match f acc x with
| Some acc' -> fold_while_some f acc' xs
| None -> None
end

let equal = List.eq
37 changes: 37 additions & 0 deletions src/util/gobYaml.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
include Yaml.Util

let (let*) = Result.bind
let (let+) r f = Result.map f r
let (>>=) = Result.bind

let option_map (f: 'a -> ('b, 'e) result) (o: 'a option): ('b option, 'e) result =
match o with
| Some x -> Result.map Option.some (f x)
| None -> Ok None

let rec list_map (f: 'a -> ('b, 'e) result) (l: 'a list): ('b list, 'e) result =
match l with
| [] -> Ok []
| x :: xs ->
let* y = f x in
let+ ys = list_map f xs in
y :: ys

let find s y =
match Yaml.Util.find s y with
| Ok (Some y'') -> Ok y''
| Ok None -> Error (`Msg ("find " ^ s))
| Error `Msg e ->
Error (`Msg ("find " ^ s ^ ": " ^ e))

let to_int y =
let+ f = to_float y in
int_of_float f

let list = function
| `A l -> Ok l
| _ -> Error (`Msg "Failed to get elements from non-array value")

let entries = function
| `O assoc -> Ok assoc
| _ -> Error (`Msg "Failed to get entries from non-object value")
81 changes: 81 additions & 0 deletions src/witness/witnessUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,84 @@ struct
else
[inv']
end

module InvariantParser =
struct
type t = {
global_vars: Cil.varinfo list;
}

let create (file: Cil.file): t =
let global_vars = List.filter_map (function
| Cil.GVar (v, _, _)
| Cil.GFun ({svar=v; _}, _) -> Some v
| _ -> None
) file.globals
in
{global_vars}

let parse_cabs (inv: string): (Cabs.expression, string) result =
match Frontc.parse_standalone_exp inv with
| inv_cabs -> Ok inv_cabs
| exception (Frontc.ParseError e) ->
Errormsg.log "\n"; (* CIL prints garbage without \n before *)
Error e

let parse_cil {global_vars} ~(fundec: Cil.fundec) ~loc (inv_cabs: Cabs.expression): (Cil.exp, string) result =
let genv = Cabs2cil.genvironment in
let env = Hashtbl.copy genv in
List.iter (fun (v: Cil.varinfo) ->
Hashtbl.replace env v.vname (Cabs2cil.EnvVar v, v.vdecl)
) (fundec.sformals @ fundec.slocals);

let inv_exp_opt =
Cil.currentLoc := loc;
Cil.currentExpLoc := loc;
Cabs2cil.currentFunctionFDEC := fundec;
let old_locals = fundec.slocals in
let old_useLogicalOperators = !Cil.useLogicalOperators in
Fun.protect ~finally:(fun () ->
fundec.slocals <- old_locals; (* restore locals, Cabs2cil may mangle them by inserting temporary variables *)
Cil.useLogicalOperators := old_useLogicalOperators
) (fun () ->
Cil.useLogicalOperators := true;
Cabs2cil.convStandaloneExp ~genv ~env inv_cabs
)
in

let vars = fundec.sformals @ fundec.slocals @ global_vars in
match inv_exp_opt with
| Some inv_exp when Check.checkStandaloneExp ~vars inv_exp ->
Ok inv_exp
| _ ->
Error "parse_cil"
end

module Locator (E: Set.OrderedType) =
struct
module FileH = BatHashtbl.Make (Basetype.RawStrings)
module LocM = BatMap.Make (CilType.Location)
module ES = BatSet.Make (E)

(* for each file, locations have total order, so LocM essentially does binary search *)
type t = ES.t LocM.t FileH.t

let create () = FileH.create 100

let add (file_loc_es: t) (loc: Cil.location) (e: E.t): unit =
FileH.modify_def LocM.empty loc.file (
LocM.modify_def ES.empty loc (ES.add e)
) file_loc_es

let find_opt (file_loc_es: t) (loc: Cil.location): ES.t option =
let (let*) = Option.bind in (* TODO: move to general library *)
let* loc_es = FileH.find_option file_loc_es loc.file in
let* (_, es) = LocM.find_first_opt (fun loc' ->
CilType.Location.compare loc loc' <= 0 (* allow inexact match *)
) loc_es
in
if ES.is_empty es then
None
else
Some es
end
Loading