Skip to content

Commit

Permalink
Merge pull request #1375 from goblint/witness-invariant-typedef
Browse files Browse the repository at this point in the history
Unroll typedefs in witness invariants
  • Loading branch information
sim642 authored Apr 5, 2024
2 parents ada228e + d561941 commit 092eed3
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/cdomain/value/domains/invariantCil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ class exp_replace_original_name_visitor = object
method! vvrbl (vi: varinfo) =
ChangeTo (var_replace_original_name vi)
end
let exp_replace_original_name e =
let exp_replace_original_name =
let visitor = new exp_replace_original_name_visitor in
visitCilExpr visitor e
visitCilExpr visitor

class exp_deep_unroll_types_visitor = object
inherit nopCilVisitor
method! vtype (t: typ) =
ChangeTo (unrollTypeDeep t)
end
let exp_deep_unroll_types =
let visitor = new exp_deep_unroll_types_visitor in
visitCilExpr visitor


let var_is_in_scope scope vi =
match Cilfacade.find_scope_fundec vi with
| None -> vi.vstorage <> Static (* CIL pulls static locals into globals, but they aren't syntactically in global scope *)
| Some fd ->
| Some fd ->
if CilType.Fundec.equal fd scope then
GobConfig.get_bool "witness.invariant.all-locals" || (not @@ hasAttribute "goblint_cil_nested" vi.vattr)
else
Expand Down Expand Up @@ -75,6 +84,23 @@ let exp_contains_tmp e =
ignore (visitCilExpr visitor e);
!acc

class exp_contains_anon_type_visitor = object
inherit nopCilVisitor
method! vtype (t: typ) =
match t with
| TComp ({cname; _}, _) when BatString.starts_with_stdlib ~prefix:"__anon" cname ->
raise Stdlib.Exit
| _ ->
DoChildren
end
let exp_contains_anon_type =
let visitor = new exp_contains_anon_type_visitor in
fun e ->
match visitCilExpr visitor e with
| _ -> false
| exception Stdlib.Exit -> true


(* TODO: synchronize magic constant with BaseDomain *)
let var_is_heap {vname; _} = BatString.starts_with vname "(alloc@"

Expand Down
6 changes: 6 additions & 0 deletions src/config/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,12 @@
"description": "Emit non-standard Goblint-specific invariants. Currently array invariants with all_index offsets.",
"type": "boolean",
"default": false
},
"typedefs": {
"title": "witness.invariant.typedefs",
"description": "Emit invariants with typedef-ed types (e.g. in casts). Our validator cannot parse these.",
"type": "boolean",
"default": true
}
},
"additionalProperties": false
Expand Down
13 changes: 12 additions & 1 deletion src/witness/witnessUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,20 @@ struct
| e -> to_conjunct_set e

let process_exp inv =
let inv' = InvariantCil.exp_replace_original_name inv in
let exp_deep_unroll_types =
if GobConfig.get_bool "witness.invariant.typedefs" then
Fun.id
else
InvariantCil.exp_deep_unroll_types
in
let inv' =
inv
|> exp_deep_unroll_types
|> InvariantCil.exp_replace_original_name
in
if GobConfig.get_bool "witness.invariant.split-conjunction" then
ES.elements (pullOutCommonConjuncts inv')
|> List.filter (Fun.negate InvariantCil.exp_contains_anon_type)
else
[inv']
end
Expand Down
Loading

0 comments on commit 092eed3

Please sign in to comment.