Skip to content

Commit 7581336

Browse files
authored
Merge pull request #1908 from goblint/intdomain-torg
Remove unused `torg` parameters
2 parents 68acaef + 3985f35 commit 7581336

File tree

12 files changed

+52
-51
lines changed

12 files changed

+52
-51
lines changed

src/analyses/base.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -946,11 +946,8 @@ struct
946946
Address (AD.map array_start (eval_lv ~man st lval))
947947
| CastE (_, t, Const (CStr (x,e))) -> (* VD.top () *) eval_rv ~man st (Const (CStr (x,e))) (* TODO safe? *)
948948
| CastE (kind, t, exp) ->
949-
(let v = eval_rv ~man st exp in
950-
try
951-
VD.cast ~kind ~torg:(Cilfacade.typeOf exp) t v
952-
with Cilfacade.TypeOfError _ ->
953-
VD.cast ~kind t v)
949+
let v = eval_rv ~man st exp in
950+
VD.cast ~kind t v
954951
| SizeOf _
955952
| Real _
956953
| Imag _
@@ -2078,7 +2075,7 @@ struct
20782075
if not (ThreadIdDomain.Thread.is_main tid) then ( (* Only non-main return constitutes an implicit pthread_exit according to man page (https://github.com/goblint/analyzer/issues/1767#issuecomment-3642590227). *)
20792076
(* Evaluate exp and cast the resulting value to the void-pointer-type.
20802077
Casting to the right type here avoids precision loss on joins. *)
2081-
let rv = VD.cast ~kind:Internal ~torg:(Cilfacade.typeOf exp) Cil.voidPtrType rv in (* TODO: proper castkind *)
2078+
let rv = VD.cast ~kind:Internal Cil.voidPtrType rv in (* TODO: proper castkind *)
20822079
man.sideg (V.thread tid) (G.create_thread rv)
20832080
);
20842081
Priv.thread_return ask (priv_getg man.global) (priv_sideg man.sideg) tid st'

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,25 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): Bitfield_SOverflow with type in
263263
else
264264
top_of ik
265265

266-
let cast_to ?torg ?(no_ov=false) ik (z,o) =
266+
let cast_to ?from_ik ?(no_ov=false) ik (z,o) =
267267
let (min_ik, max_ik) = Size.range ik in
268-
let (underflow, overflow) = match torg with
268+
let (underflow, overflow) = match from_ik with
269269
| None -> (false, false) (* ik does not change *)
270-
| Some (GoblintCil.Cil.TInt (old_ik, _) | TEnum ({ekind = old_ik; _}, _)) ->
270+
| Some old_ik ->
271271
let underflow = Z.compare (BArith.min old_ik (z,o)) min_ik < 0 in
272272
let overflow = Z.compare max_ik (BArith.max old_ik (z,o)) < 0 in
273273
(underflow, overflow)
274-
| _ ->
275-
let isPos = z <: Ints_t.zero in
276-
let isNeg = o <: Ints_t.zero in
277-
let underflow = if GoblintCil.isSigned ik then (((Ints_t.of_bigint min_ik) &: z) <>: Ints_t.zero) && isNeg else isNeg in
278-
let overflow = (((!:(Ints_t.of_bigint max_ik)) &: o) <>: Ints_t.zero) && isPos in
279-
(underflow, overflow)
274+
(* | _ -> (* TODO: what is this case? was it always dead? *)
275+
let isPos = z <: Ints_t.zero in
276+
let isNeg = o <: Ints_t.zero in
277+
let underflow = if GoblintCil.isSigned ik then (((Ints_t.of_bigint min_ik) &: z) <>: Ints_t.zero) && isNeg else isNeg in
278+
let overflow = (((!:(Ints_t.of_bigint max_ik)) &: o) <>: Ints_t.zero) && isPos in
279+
(underflow, overflow) *)
280280
in
281281
let overflow_info = {underflow; overflow} in
282282
(norm ~ov:(underflow || overflow) ik (z,o), overflow_info)
283283

284-
let cast_to ~kind ?torg ?(no_ov=false) ik (z,o) =
284+
let cast_to ~kind ?from_ik ?(no_ov=false) ik (z,o) =
285285
if ik = GoblintCil.IBool then (
286286
let may_zero =
287287
if Ints_t.equal z BArith.one_mask then (* zero bit may be in every position (one_mask) *)
@@ -298,7 +298,7 @@ module BitfieldFunctor (Ints_t : IntOps.IntOps): Bitfield_SOverflow with type in
298298
(BArith.join may_zero may_one, {underflow=false; overflow=false})
299299
)
300300
else
301-
cast_to ?torg ~no_ov ik (z,o)
301+
cast_to ?from_ik ~no_ov ik (z,o)
302302

303303
let join ik b1 b2 = norm ik @@ (BArith.join b1 b2)
304304

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct
166166
| _ -> None
167167

168168
(* cast from original type to ikind, set to top if the value doesn't fit into the new type *)
169-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ?(no_ov=false) t x =
169+
let cast_to ?(suppress_ovwarn=false) ~kind ?from_ik ?(no_ov=false) t x =
170170
match x with
171171
| None -> None
172172
| Some (c, m) when m =: Z.zero ->
@@ -183,16 +183,16 @@ struct
183183
let (min_ikorg, max_ikorg) = range ikorg in
184184
ikorg = t || (max_t >=: max_ikorg && min_t <=: min_ikorg)
185185
in
186-
match Option.map Cil.unrollType torg with
187-
| Some (Cil.TInt (ikorg, _) | TEnum ({ekind = ikorg; _}, _)) when p ikorg ->
186+
match from_ik with
187+
| Some ikorg when p ikorg ->
188188
if M.tracing then M.trace "cong-cast" "some case";
189189
x
190190
| _ -> top ()
191191

192192

193-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ?no_ov (t : Cil.ikind) x =
193+
let cast_to ?(suppress_ovwarn=false) ~kind ?from_ik ?no_ov (t : Cil.ikind) x =
194194
let pretty_bool _ x = Pretty.text (string_of_bool x) in
195-
let res = cast_to ~kind ?torg ?no_ov t x in
195+
let res = cast_to ~kind ?from_ik ?no_ov t x in
196196
if M.tracing then M.trace "cong-cast" "Cast %a to %a (no_ov: %a) = %a" pretty x Cil.d_ikind t (Pretty.docOpt (pretty_bool ())) no_ov pretty res;
197197
res
198198

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct
132132
| `Definite x -> if i = x then `Eq else `Neq
133133
| `Excluded (s,r) -> if S.mem i s then `Neq else `Top
134134

135-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ?no_ov ik = function
135+
let cast_to ?(suppress_ovwarn=false) ~kind ?from_ik ?no_ov ik = function
136136
| `Excluded (s,r) ->
137137
let r' = size ik in
138138
if R.leq r r' then (* upcast -> no change *)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module Enums : S with type int_t = Z.t = struct
9797
if BISet.mem i x then `Neq
9898
else `Top
9999

100-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ?no_ov ik v = norm ik @@ match v with
100+
let cast_to ?(suppress_ovwarn=false) ~kind ?from_ik ?no_ov ik v = norm ik @@ match v with
101101
| Exc (s,r) ->
102102
let r' = size ik in
103103
if R.leq r r' then (* upcast -> no change *)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ module IntDomTupleImpl = struct
363363
let c_lognot ik =
364364
map ik {f1 = (fun (type a) (module I : SOverflow with type t = a) ?no_ov -> I.c_lognot ik)}
365365

366-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ?no_ov t =
367-
mapovc ~suppress_ovwarn ~op:(Cast kind) t {f1_ovc = (fun (type a) (module I : SOverflow with type t = a) ?no_ov -> I.cast_to ~kind ?torg ?no_ov t)}
366+
let cast_to ?(suppress_ovwarn=false) ~kind ?from_ik ?no_ov t =
367+
mapovc ~suppress_ovwarn ~op:(Cast kind) t {f1_ovc = (fun (type a) (module I : SOverflow with type t = a) ?no_ov -> I.cast_to ~kind ?from_ik ?no_ov t)}
368368

369369
(* fp: projections *)
370370
let equal_to i x =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct
138138
let maximal = function None -> None | Some (x,y) -> Some y
139139
let minimal = function None -> None | Some (x,y) -> Some x
140140

141-
let cast_to ~kind ?torg ?no_ov t = norm ~cast:true t (* norm does all overflow handling *)
141+
let cast_to ~kind ?from_ik ?no_ov t = norm ~cast:true t (* norm does all overflow handling *)
142142

143143
let widen ik x y =
144144
match x, y with

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ struct
484484
in
485485
binop x y interval_rem
486486

487-
let cast_to ~kind ?torg ?no_ov ik x = norm_intvs ~cast:true ik x
487+
let cast_to ~kind ?from_ik ?no_ov ik x = norm_intvs ~cast:true ik x
488488

489489
(*
490490
narrows down the extremeties of xs if they are equal to boundary values of the ikind with (possibly) narrower values from ys

src/cdomain/value/cdomains/intDomain0.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ struct
234234
let c_logand = lift2 I.c_logand
235235
let c_logor = lift2 I.c_logor
236236

237-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg ikind x = {v = I.cast_to ~suppress_ovwarn ~kind ~torg:(TInt(x.ikind,[])) ikind x.v; ikind}
237+
let cast_to ?(suppress_ovwarn=false) ~kind ikind x = {v = I.cast_to ~suppress_ovwarn ~kind ~from_ik:x.ikind ikind x.v; ikind}
238238

239239
let is_top_of ik x = ik = x.ikind && I.is_top_of ik x.v
240240

@@ -537,7 +537,7 @@ module SOverflowUnlifter (D : SOverflow) : S2 with type int_t = D.int_t and type
537537

538538
let neg ?no_ov ik x = fst @@ D.neg ?no_ov ik x
539539

540-
let cast_to ?suppress_ovwarn ~kind ?torg ?no_ov ik x = fst @@ D.cast_to ~kind ?torg ?no_ov ik x
540+
let cast_to ?suppress_ovwarn ~kind ?from_ik ?no_ov ik x = fst @@ D.cast_to ~kind ?from_ik ?no_ov ik x
541541

542542
let of_int ?suppress_ovwarn ik x = fst @@ D.of_int ik x
543543

@@ -605,7 +605,7 @@ struct
605605
let c_lognot n1 = of_bool (not (to_bool' n1))
606606
let c_logand n1 n2 = of_bool ((to_bool' n1) && (to_bool' n2))
607607
let c_logor n1 n2 = of_bool ((to_bool' n1) || (to_bool' n2))
608-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg t x = failwith @@ "Cast_to not implemented for " ^ (name ()) ^ "."
608+
let cast_to ?(suppress_ovwarn=false) ~kind t x = failwith @@ "Cast_to not implemented for " ^ (name ()) ^ "."
609609
let arbitrary ik = QCheck.map ~rev:Ints_t.to_int64 Ints_t.of_int64 GobQCheck.Arbitrary.int64 (* TODO: use ikind *)
610610
let invariant _ _ = Invariant.none (* TODO *)
611611
end
@@ -635,7 +635,7 @@ struct
635635

636636

637637
let name () = "flat integers"
638-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg t = function
638+
let cast_to ?(suppress_ovwarn=false) ~kind t = function
639639
| `Lifted x -> `Lifted (Base.cast_to ~kind t x)
640640
| x -> x
641641

@@ -716,7 +716,7 @@ struct
716716
include StdTop (struct type nonrec t = t let top_of = top_of end)
717717

718718
let name () = "lifted integers"
719-
let cast_to ?(suppress_ovwarn=false) ~kind ?torg t = function
719+
let cast_to ?(suppress_ovwarn=false) ~kind t = function
720720
| `Lifted x -> `Lifted (Base.cast_to ~kind t x)
721721
| x -> x
722722

@@ -789,7 +789,7 @@ module SOverflowLifter (D : S) : SOverflow with type int_t = D.int_t and type t
789789

790790
let neg ?no_ov ik x = lift @@ D.neg ?no_ov ik x
791791

792-
let cast_to ~kind ?torg ?no_ov ik x = lift @@ D.cast_to ~kind ?torg ?no_ov ik x
792+
let cast_to ~kind ?from_ik ?no_ov ik x = lift @@ D.cast_to ~kind ?from_ik ?no_ov ik x
793793

794794
let of_int ik x = lift @@ D.of_int ik x
795795

src/cdomain/value/cdomains/intDomain_intf.ml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ sig
199199

200200
(** {b Cast} *)
201201

202-
val cast_to: ?suppress_ovwarn:bool -> kind:castkind -> ?torg:Cil.typ -> Cil.ikind -> t -> t
203-
(** Cast from original type [torg] to integer type [Cil.ikind]. Currently, [torg] is only present for actual casts. The function is also called to handle overflows/wrap around after operations. In these cases (where the type stays the same) [torg] is None. *)
204-
202+
val cast_to: ?suppress_ovwarn:bool -> kind:castkind -> Cil.ikind -> t -> t
203+
(** Cast to {!Cil.ikind}.
204+
The function is also called to handle overflow/wraparound after operations. *)
205205
end
206206

207207
(** The signature of integral value domains. They need to support all integer
@@ -241,8 +241,10 @@ sig
241241
val mul : ?no_ov:bool -> Cil.ikind -> t -> t -> t
242242
val div : ?no_ov:bool -> Cil.ikind -> t -> t -> t
243243
val neg : ?no_ov:bool -> Cil.ikind -> t -> t
244-
val cast_to : ?suppress_ovwarn:bool -> kind:castkind -> ?torg:Cil.typ -> ?no_ov:bool -> Cil.ikind -> t -> t
245-
(** @param no_ov If true, assume no overflow can occur. *)
244+
val cast_to : ?suppress_ovwarn:bool -> kind:castkind -> ?from_ik:Cil.ikind -> ?no_ov:bool -> Cil.ikind -> t -> t
245+
(** Cast from [from_ik] (if known) to {!Cil.ikind}.
246+
The function is also called to handle overflow/wraparound after operations.
247+
@param no_ov If true, assume no overflow can occur. *)
246248

247249
val join: Cil.ikind -> t -> t -> t
248250
val meet: Cil.ikind -> t -> t -> t
@@ -300,7 +302,10 @@ sig
300302

301303
val neg : ?no_ov:bool -> Cil.ikind -> t -> t * overflow_info
302304

303-
val cast_to : kind:castkind -> ?torg:Cil.typ -> ?no_ov:bool -> Cil.ikind -> t -> t * overflow_info
305+
val cast_to : kind:castkind -> ?from_ik:Cil.ikind -> ?no_ov:bool -> Cil.ikind -> t -> t * overflow_info
306+
(** Cast from [from_ik] (if known) to {!Cil.ikind}.
307+
The function is also called to handle overflow/wraparound after operations.
308+
@param no_ov If true, assume no overflow can occur. *)
304309

305310
val of_int : Cil.ikind -> int_t -> t * overflow_info
306311

0 commit comments

Comments
 (0)