Skip to content

Commit

Permalink
Add option witness.invariant.typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Mar 4, 2024
1 parent a6b7f4e commit d561941
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 2 deletions.
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
8 changes: 7 additions & 1 deletion src/witness/witnessUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ struct
| e -> to_conjunct_set e

let process_exp inv =
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
|> InvariantCil.exp_deep_unroll_types
|> exp_deep_unroll_types
|> InvariantCil.exp_replace_original_name
in
if GobConfig.get_bool "witness.invariant.split-conjunction" then
Expand Down
166 changes: 165 additions & 1 deletion tests/regression/witness/typedef.t/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ goblint --enable witness.yaml.enabled --set witness.yaml.entry-types '["location_invariant"]' typedef.c
$ goblint --enable witness.yaml.enabled --set witness.yaml.entry-types '["location_invariant"]' --disable witness.invariant.typedefs typedef.c
[Info][Deadcode] Logical lines of code (LLoC) summary:
live: 6
dead: 0
Expand Down Expand Up @@ -150,3 +150,167 @@
string: x == 42
type: assertion
format: C

$ goblint --enable witness.yaml.enabled --set witness.yaml.entry-types '["location_invariant"]' --enable witness.invariant.typedefs typedef.c
[Info][Deadcode] Logical lines of code (LLoC) summary:
live: 6
dead: 0
total lines: 6
[Info][Witness] witness generation summary:
total generation entries: 14

$ yamlWitnessStrip < witness.yml
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: x == 42
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: q == (void *)(& a)
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: p == (void *)(& x)
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: a.f == 43
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 14
column: 2
function: main
location_invariant:
string: ((s *)q)->f == 43
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 13
column: 2
function: main
location_invariant:
string: x == 42
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 13
column: 2
function: main
location_invariant:
string: p == (void *)(& x)
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 13
column: 2
function: main
location_invariant:
string: a.f == 43
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 13
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 12
column: 2
function: main
location_invariant:
string: x == 42
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 12
column: 2
function: main
location_invariant:
string: p == (void *)(& x)
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 12
column: 2
function: main
location_invariant:
string: '*((myint *)p) == 42'
type: assertion
format: C
- entry_type: location_invariant
location:
file_name: typedef.c
file_hash: $FILE_HASH
line: 9
column: 2
function: main
location_invariant:
string: x == 42
type: assertion
format: C

0 comments on commit d561941

Please sign in to comment.