Skip to content

Commit 6f7c881

Browse files
committed
Fix GobApron.Linxexpr0.neg not negating all dimensions
1 parent 9257a01 commit 6f7c881

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

src/cdomains/apron/gobApron.apron.ml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ struct
4444
(** Negate linear expression. *)
4545
let neg (linexpr0: t): t =
4646
let r = copy linexpr0 in
47-
let n = Linexpr0.get_size r in
48-
for i = 0 to n - 1 do
49-
Linexpr0.set_coeff r i (Coeff.neg (Linexpr0.get_coeff r i))
50-
done;
51-
Linexpr0.set_cst r (Coeff.neg (Linexpr0.get_cst r));
47+
Linexpr0.iter (fun c i ->
48+
Linexpr0.set_coeff r i (Coeff.neg c)
49+
) linexpr0;
50+
Linexpr0.set_cst r (Coeff.neg (Linexpr0.get_cst linexpr0));
5251
r
5352
end
5453

tests/regression/36-apron/01-octagon_simple.t

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Without diff-box:
2121
[Warning][Deadcode][CWE-571] condition '1' (possibly inserted by CIL) is always true (01-octagon_simple.c:44:10-44:11)
2222
[Info][Witness] witness generation summary:
2323
location invariants: 0
24-
loop invariants: 14
24+
loop invariants: 16
2525
flow-insensitive invariants: 0
2626
total generation entries: 1
2727

@@ -64,6 +64,15 @@ Without diff-box:
6464
function: main
6565
value: (long long )X + 2147483647LL >= (long long )N
6666
format: c_expression
67+
- invariant:
68+
type: loop_invariant
69+
location:
70+
file_name: 01-octagon_simple.c
71+
line: 10
72+
column: 3
73+
function: main
74+
value: (long long )X >= 0LL
75+
format: c_expression
6776
- invariant:
6877
type: loop_invariant
6978
location:
@@ -127,6 +136,15 @@ Without diff-box:
127136
function: two
128137
value: (long long )X + 2147483647LL >= (long long )N
129138
format: c_expression
139+
- invariant:
140+
type: loop_invariant
141+
location:
142+
file_name: 01-octagon_simple.c
143+
line: 44
144+
column: 3
145+
function: two
146+
value: (long long )X >= 0LL
147+
format: c_expression
130148
- invariant:
131149
type: loop_invariant
132150
location:
@@ -253,6 +271,15 @@ Compare witnesses:
253271
function: two
254272
value: 2147483647LL >= (long long )N
255273
format: c_expression
274+
- invariant:
275+
type: loop_invariant
276+
location:
277+
file_name: 01-octagon_simple.c
278+
line: 44
279+
column: 3
280+
function: two
281+
value: (long long )X >= 0LL
282+
format: c_expression
256283
- invariant:
257284
type: loop_invariant
258285
location:
@@ -289,6 +316,15 @@ Compare witnesses:
289316
function: main
290317
value: 2147483647LL >= (long long )N
291318
format: c_expression
319+
- invariant:
320+
type: loop_invariant
321+
location:
322+
file_name: 01-octagon_simple.c
323+
line: 10
324+
column: 3
325+
function: main
326+
value: (long long )X >= 0LL
327+
format: c_expression
292328
- invariant:
293329
type: loop_invariant
294330
location:

tests/regression/89-apron3/03-octagon_simplest.t

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ Without diff-box:
88
[Warning][Deadcode][CWE-570] condition 'N < 0' is always false (03-octagon_simplest.c:9:6-9:11)
99
[Info][Witness] witness generation summary:
1010
location invariants: 0
11-
loop invariants: 15
11+
loop invariants: 17
1212
flow-insensitive invariants: 0
1313
total generation entries: 1
1414

15-
TODO: Should have Y == 0
1615
$ yamlWitnessStrip < witness.yml | tee witness-disable-diff-box.yml
1716
- entry_type: invariant_set
1817
content:
@@ -70,6 +69,15 @@ TODO: Should have Y == 0
7069
function: main
7170
value: (long long )X >= (long long )Y
7271
format: c_expression
72+
- invariant:
73+
type: loop_invariant
74+
location:
75+
file_name: 03-octagon_simplest.c
76+
line: 11
77+
column: 3
78+
function: main
79+
value: (long long )X >= 0LL
80+
format: c_expression
7381
- invariant:
7482
type: loop_invariant
7583
location:
@@ -106,6 +114,15 @@ TODO: Should have Y == 0
106114
function: main
107115
value: (long long )Y + 2147483647LL >= (long long )X
108116
format: c_expression
117+
- invariant:
118+
type: loop_invariant
119+
location:
120+
file_name: 03-octagon_simplest.c
121+
line: 11
122+
column: 3
123+
function: main
124+
value: (long long )Y == 0LL
125+
format: c_expression
109126
- invariant:
110127
type: loop_invariant
111128
location:
@@ -238,6 +255,15 @@ Compare witnesses:
238255
function: main
239256
value: 2147483647LL >= (long long )N
240257
format: c_expression
258+
- invariant:
259+
type: loop_invariant
260+
location:
261+
file_name: 03-octagon_simplest.c
262+
line: 11
263+
column: 3
264+
function: main
265+
value: (long long )Y == 0LL
266+
format: c_expression
241267
- invariant:
242268
type: loop_invariant
243269
location:
@@ -265,6 +291,15 @@ Compare witnesses:
265291
function: main
266292
value: (long long )Y + (long long )N >= 0LL
267293
format: c_expression
294+
- invariant:
295+
type: loop_invariant
296+
location:
297+
file_name: 03-octagon_simplest.c
298+
line: 11
299+
column: 3
300+
function: main
301+
value: (long long )X >= 0LL
302+
format: c_expression
268303
- invariant:
269304
type: loop_invariant
270305
location:

0 commit comments

Comments
 (0)