You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/cdomain/value/cdomains/int/intervalSetDomain.ml
+16-13Lines changed: 16 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -173,7 +173,12 @@ struct
173
173
letbinary_op_with_normop (ik:ikind) (x: t) (y: t) : t*overflow_info =match x, y with
174
174
|[], _ -> ([],{overflow=false; underflow=false})
175
175
|_, [] -> ([],{overflow=false; underflow=false})
176
-
|_, _ -> norm_intvs ik @@List.concat_map (fun (x,y) -> [op x y]) (BatList.cartesian_product x y)
176
+
|_, _ -> norm_intvs ik @@List.map (fun (x,y) -> op x y) (BatList.cartesian_product x y)
177
+
178
+
letbinary_op_concat_with_normop (ik:ikind) (x: t) (y: t) : t*overflow_info =match x, y with
179
+
|[], _ -> ([],{overflow=false; underflow=false})
180
+
|_, [] -> ([],{overflow=false; underflow=false})
181
+
|_, _ -> norm_intvs ik @@List.concat_map (fun (x,y) -> op x y) (BatList.cartesian_product x y)
177
182
178
183
letbinary_op_with_ovc (x: t) (y: t) op : t*overflow_info =match x, y with
179
184
|[], _ -> ([],{overflow=false; underflow=false})
@@ -187,7 +192,7 @@ struct
187
192
188
193
letunary_op_with_normop (ik:ikind) (x: t) =match x with
189
194
|[] -> ([],{overflow=false; underflow=false})
190
-
|_ -> norm_intvs ik @@List.concat_map (funx -> [op x]) x
195
+
|_ -> norm_intvs ik @@List.map op x
191
196
192
197
letrec leq (xs: t) (ys: t) =
193
198
letleq_interval (al, au) (bl, bu) = al >=. bl && au <=. bu in
@@ -358,17 +363,15 @@ struct
358
363
letneg?no_ov= unary_op_with_norm IArith.neg
359
364
360
365
letdiv?no_ovikxy=
361
-
letrec interval_divx (y1, y2) =begin
362
-
lettop_ofik= top_of ik |>List.hd in
363
-
letis_zerov= v =.Ints_t.zero in
364
-
match y1, y2 with
365
-
|l, uwhen is_zero l && is_zero u -> top_of ik
366
-
|l, _when is_zero l -> interval_div x (Ints_t.one,y2)
367
-
|_, uwhen is_zero u -> interval_div x (y1, Ints_t.(neg one))
368
-
|_when leq (of_int ik (Ints_t.zero) |> fst) ([(y1,y2)]) -> top_of ik
369
-
|_ -> IArith.div x (y1, y2)
370
-
end
371
-
in binary_op_with_norm interval_div ik x y
366
+
letrec interval_divxy=
367
+
let (neg, pos) =IArith.div x y in
368
+
let r =List.filter_map Fun.id [neg; pos] in
369
+
if leq (of_int ik Ints_t.zero |> fst) [y] then
370
+
top_of ik @ r (* keep r because they might overflow, but top doesn't *)
371
+
else
372
+
r (* should always be singleton, because if there's a negative and a positive side, then it must've included zero, which is already handled by previous case *)
Excludes 0 from denominator - must be handled as desired by caller.
366
+
367
+
@return negative and positive denominator cases separately, if they exist.
368
+
369
+
@see <https://mine.perso.lip6.fr/publi/article-mine-FTiPL17.pdf> Miné, A. Tutorial on Static Inference of Numeric Invariants by Abstract Interpretation. Figure 4.6. *)
370
+
letdiv (a, b) (c, d) =
371
+
let pos =
372
+
ifInts_t.(compare one d) <=0then
373
+
let c =Ints_t.(max one c) in
374
+
Some (Ints_t.(min (div a c) (div a d), max (div b c) (div b d)))
375
+
else
376
+
None
377
+
in
378
+
let neg =
379
+
ifInts_t.(compare c zero) <0then
380
+
let d =Ints_t.(min d (neg one)) in
381
+
Some (Ints_t.(min (div b c) (div b d), max (div a c) (div a d)))
0 commit comments