Skip to content

Commit ef5b7be

Browse files
Interval32: Special handling for mul if one argument must be zero
1 parent 11f2120 commit ef5b7be

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/cdomains/intDomain.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,18 @@ struct
361361
meet (bit Int64.rem x y) range
362362

363363
let mul x y =
364-
on_top_return_top_bin x y @@
365-
match x, y with
366-
| None, None -> bot ()
367-
| None, _ | _, None -> raise (ArithmeticOnIntegerBot (Printf.sprintf "%s op %s" (short 80 x) (short 80 y)))
368-
| Some (x1,x2), Some (y1,y2) ->
369-
let x1y1 = (Int64.mul x1 y1) in let x1y2 = (Int64.mul x1 y2) in
370-
let x2y1 = (Int64.mul x2 y1) in let x2y2 = (Int64.mul x2 y2) in
371-
norm @@ Some ((min (min x1y1 x1y2) (min x2y1 x2y2)),
372-
(max (max x1y1 x1y2) (max x2y1 x2y2)))
364+
if (is_top x || is_top y) && to_int x <> Some 0L && to_int y <> Some 0L then
365+
(* if one of the argument is zero, the result must be zero, even if the value is outside the range of Interval32 *)
366+
top ()
367+
else
368+
match x, y with
369+
| None, None -> bot ()
370+
| None, _ | _, None -> raise (ArithmeticOnIntegerBot (Printf.sprintf "%s op %s" (short 80 x) (short 80 y)))
371+
| Some (x1,x2), Some (y1,y2) ->
372+
let x1y1 = (Int64.mul x1 y1) in let x1y2 = (Int64.mul x1 y2) in
373+
let x2y1 = (Int64.mul x2 y1) in let x2y2 = (Int64.mul x2 y2) in
374+
norm @@ Some ((min (min x1y1 x1y2) (min x2y1 x2y2)),
375+
(max (max x1y1 x1y2) (max x2y1 x2y2)))
373376

374377
let rec div x y =
375378
on_top_return_top_bin x y @@

tests/regression/24-octagon/02-octagon_interprocudral.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ int f1() {
1111

1212
one = two;
1313

14-
// We no longer compute with "top" in the interval domain,
15-
// leading to a loss of precision here.
16-
// Thus the three asserts are here marked with "UNKNOWN".
17-
assert(one - two == 0); // UNKNOWN
14+
assert(one - two == 0);
1815
x = f2(one,two);
19-
assert(one - two == 0); // UNKNOWN
16+
assert(one - two == 0);
2017
assert(x == 48);
2118
}
2219

2320
int f2(int a, int b) {
24-
assert(a-b == 0); // UNKNOWN
21+
assert(a-b == 0);
2522

2623
return 48;
2724
}

0 commit comments

Comments
 (0)