Skip to content

Commit

Permalink
Unroll typedefs for witness invariants
Browse files Browse the repository at this point in the history
We have problems parsing them for validation: goblint/cil#159.
  • Loading branch information
sim642 committed Mar 1, 2024
1 parent e4231ef commit 0aa6a90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
13 changes: 11 additions & 2 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 e = (* TODO: curry to create object only once *)
let visitor = new exp_replace_original_name_visitor in
visitCilExpr visitor e

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
6 changes: 5 additions & 1 deletion src/witness/witnessUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ struct
| e -> to_conjunct_set e

let process_exp inv =
let inv' = InvariantCil.exp_replace_original_name inv in
let inv' =
inv
|> InvariantCil.exp_deep_unroll_types
|> InvariantCil.exp_replace_original_name
in
if GobConfig.get_bool "witness.invariant.split-conjunction" then
ES.elements (pullOutCommonConjuncts inv')
else
Expand Down
8 changes: 4 additions & 4 deletions tests/regression/witness/typedef.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
string: '*((int *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
Expand All @@ -70,7 +70,7 @@
column: 2
function: main
location_invariant:
string: ((s *)q)->f == 43
string: ((struct __anonstruct_s_109580352 *)q)->f == 43
type: assertion
format: C
- entry_type: location_invariant
Expand Down Expand Up @@ -114,7 +114,7 @@
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
string: '*((int *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
Expand Down Expand Up @@ -147,7 +147,7 @@
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
string: '*((int *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
Expand Down

0 comments on commit 0aa6a90

Please sign in to comment.