Skip to content

Commit 62e97b9

Browse files
authored
Merge pull request #1794 from goblint/create2-check_ov
Remove overflow checks for integer constants
2 parents e011a10 + 3da69f5 commit 62e97b9

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

src/analyses/base.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,7 @@ struct
803803
(* Integer literals *)
804804
(* seems like constFold already converts CChr to CInt *)
805805
| Const (CChr x) -> eval_rv ~man st (Const (charConstToInt x)) (* char becomes int, see Cil doc/ISO C 6.4.4.4.10 *)
806-
| Const (CInt (num,ikind,str)) ->
807-
GobOption.iter (fun x -> if M.tracing then M.tracel "casto" "CInt (%s, %a, %s)" (Z.to_string num) d_ikind ikind x) str;
808-
Int (ID.cast_to ikind (IntDomain.of_const (num,ikind,str)))
806+
| Const (CInt (num,ikind,str)) -> Int (IntDomain.of_const (num,ikind,str)) (* no cast to ikind needed: CIL ensures that the literal fits ikind, either by silently truncating it (!) or having an explicit CastE around this *)
809807
| Const (CReal (_,fkind, Some str)) when not (Cilfacade.isComplexFKind fkind) -> Float (FD.of_string fkind str) (* prefer parsing from string due to higher precision *)
810808
| Const (CReal (num, fkind, None)) when not (Cilfacade.isComplexFKind fkind) && num = 0.0 -> Float (FD.of_const fkind num) (* constant 0 is ok, CIL creates these for zero-initializers; it is safe across float types *)
811809
| Const (CReal (_, fkind, None)) when not (Cilfacade.isComplexFKind fkind) -> assert false (* Cil does not create other CReal without string representation *)

src/cdomain/value/cdomains/int/intDomTuple.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module IntDomTupleImpl = struct
119119
let bot_of = create { fi = fun (type a) (module I:SOverflow with type t = a) -> I.bot_of }
120120
let of_bool ik = create { fi = fun (type a) (module I:SOverflow with type t = a) -> I.of_bool ik }
121121
let of_excl_list ik = create2 { fi2 = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.of_excl_list ik}
122-
let of_int ik = create2_ovc ik { fi2_ovc = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.of_int ik }
122+
let of_int ?(suppress_ovwarn=false) ik = create2_ovc ~suppress_ovwarn ik { fi2_ovc = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.of_int ik }
123123
let starting ?(suppress_ovwarn=false) ik = create2_ovc ~suppress_ovwarn ik { fi2_ovc = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.starting ik }
124124
let ending ?(suppress_ovwarn=false) ik = create2_ovc ~suppress_ovwarn ik { fi2_ovc = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.ending ik }
125125
let of_interval ?(suppress_ovwarn=false) ik = create2_ovc ~suppress_ovwarn ik { fi2_ovc = fun (type a) (module I:SOverflow with type t = a and type int_t = int_t) -> I.of_interval ik }
@@ -558,4 +558,4 @@ struct
558558
let no_bitfield (x: I.t) = {x with v = IntDomTupleImpl.no_bitfield x.v}
559559
end
560560

561-
let of_const (i, ik, str) = IntDomTuple.of_int ik i
561+
let of_const (i, ik, str) = IntDomTuple.of_int ~suppress_ovwarn:true ik i

src/cdomain/value/cdomains/intDomain0.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct
166166
let tag x = I.tag x.v
167167
let arbitrary ik = failwith @@ "Arbitrary not implement for " ^ (name ()) ^ "."
168168
let to_int x = I.to_int x.v
169-
let of_int ikind x = { v = I.of_int ikind x; ikind}
169+
let of_int ?(suppress_ovwarn=false) ikind x = { v = I.of_int ~suppress_ovwarn ikind x; ikind}
170170
let equal_to i x = I.equal_to i x.v
171171
let to_bool x = I.to_bool x.v
172172
let of_bool ikind b = { v = I.of_bool ikind b; ikind}
@@ -511,7 +511,7 @@ module SOverflowUnlifter (D : SOverflow) : S2 with type int_t = D.int_t and type
511511

512512
let cast_to ?suppress_ovwarn ?torg ?no_ov ik x = fst @@ D.cast_to ?torg ?no_ov ik x
513513

514-
let of_int ik x = fst @@ D.of_int ik x
514+
let of_int ?suppress_ovwarn ik x = fst @@ D.of_int ik x
515515

516516
let of_interval ?suppress_ovwarn ik x = fst @@ D.of_interval ik x
517517

src/cdomain/value/cdomains/intDomain_intf.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ module type S2 =
279279
sig
280280
include S
281281

282+
val of_int: ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
282283
val starting : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
283284
val ending : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
284285
val of_interval: ?suppress_ovwarn:bool -> Cil.ikind -> int_t * int_t -> t
@@ -321,7 +322,7 @@ sig
321322
include Lattice.Top with type t := t
322323
include Arith with type t:=t
323324

324-
val of_int: Cil.ikind -> int_t -> t
325+
val of_int: ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
325326
(** Transform an integer literal to your internal domain representation with the specified ikind. *)
326327

327328
val of_bool: Cil.ikind -> bool -> t

src/cdomains/unionFind.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ module T = struct
226226
let offset_to_index ?typ offset =
227227
let ptr_diff_ikind = Cilfacade.ptrdiff_ikind () in
228228
let offset_in_bytes = PreValueDomain.Offs.to_index ?typ offset in
229-
let bytes_to_bits = IntDomain.of_const (Z.of_int 8, ptr_diff_ikind, None) in
229+
let bytes_to_bits = IntDomain.IntDomTuple.of_int ptr_diff_ikind (Z.of_int 8) in
230230
IntDomain.IntDomTuple.mul bytes_to_bits offset_in_bytes
231231

232232
(** Convert a Cil offset to an integer offset. *)

src/domains/intDomainProperties.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module MakeS2 (I: S): S2 =
2929
struct
3030
include I
3131

32+
let of_int ?suppress_ovwarn ik x = of_int ik x
3233
let starting ?suppress_ovwarn ik x = starting ik x
3334
let ending ?suppress_ovwarn ik x = ending ik x
3435
let of_interval ?suppress_ovwarn ik x = of_interval ik x

0 commit comments

Comments
 (0)