Skip to content

Commit 950cf9b

Browse files
committed
Fix variable counting with ana.apron.invariant.one-var
1 parent 9086c99 commit 950cf9b

File tree

3 files changed

+11
-113
lines changed

3 files changed

+11
-113
lines changed

src/analyses/apron/apronAnalysis.apron.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ struct
542542
|> List.enum
543543
|> Enum.filter_map (fun (lincons1: Lincons1.t) ->
544544
(* filter one-vars *)
545-
if one_var || Apron.Linexpr0.get_size lincons1.lincons0.linexpr0 >= 2 then
545+
if one_var || Lincons1.num_vars lincons1 >= 2 then
546546
CilOfApron.cil_exp_of_lincons1 lincons1
547547
|> Option.map e_inv
548548
|> Option.filter (fun exp -> not (InvariantCil.exp_contains_tmp exp) && InvariantCil.exp_is_in_scope scope exp)

src/cdomains/apron/apronDomain.apron.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ struct
158158

159159
let show = Format.asprintf "%a" print
160160
let compare x y = String.compare (show x) (show y) (* HACK *)
161+
162+
let num_vars x =
163+
(* Apron.Linexpr0.get_size returns some internal nonsense, so we count ourselves. *)
164+
let size = ref 0 in
165+
Lincons1.iter (fun coeff var ->
166+
if not (Apron.Coeff.is_zero coeff) then
167+
incr size
168+
) x;
169+
!size
161170
end
162171

163172
module Lincons1Set =

tests/regression/36-apron/12-traces-min-rpb1.t

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -14,81 +14,14 @@
1414
write with [mhp:{tid=[main, t_fun@12-traces-min-rpb1.c:25:3-25:40]}, lock:{A}, thread:[main, t_fun@12-traces-min-rpb1.c:25:3-25:40]] (conf. 110) (12-traces-min-rpb1.c:15:3-15:8)
1515
read with [mhp:{tid=[main]; created={[main, t_fun@12-traces-min-rpb1.c:25:3-25:40]}}, thread:[main]] (conf. 110) (12-traces-min-rpb1.c:27:3-27:26)
1616
[Info][Witness] witness generation summary:
17-
total: 12
17+
total: 3
1818
[Info][Race] Memory locations race summary:
1919
safe: 0
2020
vulnerable: 0
2121
unsafe: 2
2222
total: 2
2323

2424
$ yamlWitnessStrip < witness.yml
25-
- entry_type: precondition_loop_invariant
26-
location:
27-
file_name: 12-traces-min-rpb1.c
28-
file_hash: $STRIPPED_FILE_HASH
29-
line: 29
30-
column: 2
31-
function: main
32-
loop_invariant:
33-
string: 2147483648LL + (long long )g >= 0LL
34-
type: assertion
35-
format: C
36-
precondition:
37-
string: -1LL + (long long )h == 0LL && -1LL + (long long )g == 0LL
38-
type: assertion
39-
format: C
40-
- entry_type: precondition_loop_invariant
41-
location:
42-
file_name: 12-traces-min-rpb1.c
43-
file_hash: $STRIPPED_FILE_HASH
44-
line: 29
45-
column: 2
46-
function: main
47-
loop_invariant:
48-
string: 2147483647LL - (long long )g >= 0LL
49-
type: assertion
50-
format: C
51-
precondition:
52-
string: -1LL + (long long )h == 0LL && -1LL + (long long )g == 0LL
53-
type: assertion
54-
format: C
55-
- entry_type: precondition_loop_invariant
56-
location:
57-
file_name: 12-traces-min-rpb1.c
58-
file_hash: $STRIPPED_FILE_HASH
59-
line: 29
60-
column: 2
61-
function: main
62-
loop_invariant:
63-
string: (0LL - (long long )g) + (long long )h == 0LL
64-
type: assertion
65-
format: C
66-
precondition:
67-
string: -1LL + (long long )h == 0LL && -1LL + (long long )g == 0LL
68-
type: assertion
69-
format: C
70-
- entry_type: loop_invariant
71-
location:
72-
file_name: 12-traces-min-rpb1.c
73-
file_hash: $STRIPPED_FILE_HASH
74-
line: 29
75-
column: 2
76-
function: main
77-
loop_invariant:
78-
string: 2147483648LL + (long long )g >= 0LL
79-
type: assertion
80-
format: C
81-
- entry_type: loop_invariant
82-
location:
83-
file_name: 12-traces-min-rpb1.c
84-
file_hash: $STRIPPED_FILE_HASH
85-
line: 29
86-
column: 2
87-
function: main
88-
loop_invariant:
89-
string: 2147483647LL - (long long )g >= 0LL
90-
type: assertion
91-
format: C
9225
- entry_type: loop_invariant
9326
location:
9427
file_name: 12-traces-min-rpb1.c
@@ -100,28 +33,6 @@
10033
string: (0LL - (long long )g) + (long long )h == 0LL
10134
type: assertion
10235
format: C
103-
- entry_type: loop_invariant
104-
location:
105-
file_name: 12-traces-min-rpb1.c
106-
file_hash: $STRIPPED_FILE_HASH
107-
line: 19
108-
column: 2
109-
function: t_fun
110-
loop_invariant:
111-
string: 2147483648LL + (long long )g >= 0LL
112-
type: assertion
113-
format: C
114-
- entry_type: loop_invariant
115-
location:
116-
file_name: 12-traces-min-rpb1.c
117-
file_hash: $STRIPPED_FILE_HASH
118-
line: 19
119-
column: 2
120-
function: t_fun
121-
loop_invariant:
122-
string: 2147483647LL - (long long )g >= 0LL
123-
type: assertion
124-
format: C
12536
- entry_type: loop_invariant
12637
location:
12738
file_name: 12-traces-min-rpb1.c
@@ -133,28 +44,6 @@
13344
string: (0LL - (long long )g) + (long long )h == 0LL
13445
type: assertion
13546
format: C
136-
- entry_type: loop_invariant
137-
location:
138-
file_name: 12-traces-min-rpb1.c
139-
file_hash: $STRIPPED_FILE_HASH
140-
line: 14
141-
column: 2
142-
function: t_fun
143-
loop_invariant:
144-
string: 2147483648LL + (long long )g >= 0LL
145-
type: assertion
146-
format: C
147-
- entry_type: loop_invariant
148-
location:
149-
file_name: 12-traces-min-rpb1.c
150-
file_hash: $STRIPPED_FILE_HASH
151-
line: 14
152-
column: 2
153-
function: t_fun
154-
loop_invariant:
155-
string: 2147483647LL - (long long )g >= 0LL
156-
type: assertion
157-
format: C
15847
- entry_type: loop_invariant
15948
location:
16049
file_name: 12-traces-min-rpb1.c

0 commit comments

Comments
 (0)