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

Unroll typedefs in witness invariants #1375

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -2474,6 +2474,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 @@ -160,9 +160,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
Loading