-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathintDomain.mli
More file actions
450 lines (305 loc) · 13.7 KB
/
intDomain.mli
File metadata and controls
450 lines (305 loc) · 13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
(** Abstract domains for C integers. *)
open GoblintCil
val should_wrap: Cil.ikind -> bool
val should_ignore_overflow: Cil.ikind -> bool
val reset_lazy: unit -> unit
type overflow_info = { overflow: bool; underflow: bool;}
module type Arith =
sig
type t
(** {b Arithmetic operators} *)
val neg: t -> t
(** Negating an integer value: [-x] *)
val add: t -> t -> t
(** Addition: [x + y] *)
val sub: t -> t -> t
(** Subtraction: [x - y] *)
val mul: t -> t -> t
(** Multiplication: [x * y] *)
val div: t -> t -> t
(** Division: [x / y] *)
val rem: t -> t -> t
(** Integer remainder: [x % y] *)
(** {b Comparison operators} *)
val lt: t -> t -> t
(** Less than: [x < y] *)
val gt: t -> t -> t
(** Greater than: [x > y] *)
val le: t -> t -> t
(** Less than or equal: [x <= y] *)
val ge: t -> t -> t
(** Greater than or equal: [x >= y] *)
val eq: t -> t -> t
(** Equal to: [x == y] *)
val ne: t -> t -> t
(** Not equal to: [x != y] *)
(** {b Bitwise logical operators} *)
val lognot: t -> t
(** Bitwise logical not (one's complement): [~x] *)
val logand: t -> t -> t
(** Bitwise logical and: [x & y] *)
val logor : t -> t -> t
(** Bitwise logical or: [x | y] *)
val logxor: t -> t -> t
(** Bitwise logical exclusive or: [x ^ y] *)
val shift_left : t -> t -> t
(** Shifting bits left: [x << y] *)
val shift_right: t -> t -> t
(** Shifting bits right: [x >> y] *)
(** {b Logical operators} *)
val c_lognot: t -> t
(** Logical not: [!x] *)
val c_logand: t -> t -> t
(** Logical and: [x && y] *)
val c_logor : t -> t -> t
(** Logical or: [x || y] *)
end
module type ArithIkind =
sig
type t
(** {b Arithmetic operators} *)
val neg: Cil.ikind -> t -> t
(** Negating an integer value: [-x] *)
val add: Cil.ikind -> t -> t -> t
(** Addition: [x + y] *)
val sub: Cil.ikind -> t -> t -> t
(** Subtraction: [x - y] *)
val mul: Cil.ikind -> t -> t -> t
(** Multiplication: [x * y] *)
val div: Cil.ikind -> t -> t -> t
(** Division: [x / y] *)
val rem: Cil.ikind -> t -> t -> t
(** Integer remainder: [x % y] *)
(** {b Comparison operators} *)
val lt: Cil.ikind -> t -> t -> t
(** Less than: [x < y] *)
val gt: Cil.ikind -> t -> t -> t
(** Greater than: [x > y] *)
val le: Cil.ikind -> t -> t -> t
(** Less than or equal: [x <= y] *)
val ge: Cil.ikind -> t -> t -> t
(** Greater than or equal: [x >= y] *)
val eq: Cil.ikind -> t -> t -> t
(** Equal to: [x == y] *)
val ne: Cil.ikind -> t -> t -> t
(** Not equal to: [x != y] *)
(** {b Bit operators} *)
val lognot: Cil.ikind -> t -> t
(** Bitwise not (one's complement): [~x] *)
val logand: Cil.ikind -> t -> t -> t
(** Bitwise and: [x & y] *)
val logor : Cil.ikind -> t -> t -> t
(** Bitwise or: [x | y] *)
val logxor: Cil.ikind -> t -> t -> t
(** Bitwise exclusive or: [x ^ y] *)
val shift_left : Cil.ikind -> t -> t -> t
(** Shifting bits left: [x << y] *)
val shift_right: Cil.ikind -> t -> t -> t
(** Shifting bits right: [x >> y] *)
(** {b Logical operators} *)
val c_lognot: Cil.ikind -> t -> t
(** Logical not: [!x] *)
val c_logand: Cil.ikind -> t -> t -> t
(** Logical and: [x && y] *)
val c_logor : Cil.ikind -> t -> t -> t
(** Logical or: [x || y] *)
end
(* Shared signature of IntDomain implementations and the lifted IntDomains *)
module type B =
sig
include Lattice.PO
include Lattice.Bot with type t := t
type int_t
(** {b Accessing values of the ADT} *)
val bot_of: Cil.ikind -> t
val top_of: Cil.ikind -> t
val to_int: t -> int_t option
(** Return a single integer value if the value is a known constant, otherwise
* don't return anything. *)
val equal_to: int_t -> t -> [`Eq | `Neq | `Top]
val to_bool: t -> bool option
(** Give a boolean interpretation of an abstract value if possible, otherwise
* don't return anything.*)
val to_excl_list: t -> (int_t list * (int64 * int64)) option
(** Gives a list representation of the excluded values from included range of bits if possible. *)
val of_excl_list: Cil.ikind -> int_t list -> t
(** Creates an exclusion set from a given list of integers. *)
val is_excl_list: t -> bool
(** Checks if the element is an exclusion set. *)
val to_incl_list: t -> int_t list option
(** Gives a list representation of the included values if possible. *)
val maximal : t -> int_t option
val minimal : t -> int_t option
(** {b Cast} *)
val cast_to: ?suppress_ovwarn:bool -> ?torg:Cil.typ -> Cil.ikind -> t -> t
(** 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. *)
end
(** The signature of integral value domains. They need to support all integer
* operations that are allowed in C *)
module type IkindUnawareS =
sig
include B
include Lattice.Top with type t := t
include Arith with type t:= t
val starting : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val ending : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val of_int: int_t -> t
(** Transform an integer literal to your internal domain representation. *)
val of_bool: bool -> t
(** Transform a known boolean value to the default internal representation. It
* should follow C: [of_bool true = of_int 1] and [of_bool false = of_int 0]. *)
val of_interval: ?suppress_ovwarn:bool -> Cil.ikind -> int_t * int_t -> t
val of_congruence: Cil.ikind -> int_t * int_t -> t
val of_bitfield: Cil.ikind -> int_t * int_t -> t
val arbitrary: unit -> t QCheck.arbitrary
val invariant: Cil.exp -> t -> Invariant.t
end
(** Interface of IntDomain implementations that do not take ikinds for arithmetic operations yet.
TODO: Should be ported to S in the future. *)
module type S =
sig
include B
include ArithIkind with type t:= t
val add : ?no_ov:bool -> Cil.ikind -> t -> t -> t
val sub : ?no_ov:bool -> Cil.ikind -> t -> t -> t
val mul : ?no_ov:bool -> Cil.ikind -> t -> t -> t
val div : ?no_ov:bool -> Cil.ikind -> t -> t -> t
val neg : ?no_ov:bool -> Cil.ikind -> t -> t
val cast_to : ?suppress_ovwarn:bool -> ?torg:Cil.typ -> ?no_ov:bool -> Cil.ikind -> t -> t
(** @param no_ov If true, assume no overflow can occur. *)
val join: Cil.ikind -> t -> t -> t
val meet: Cil.ikind -> t -> t -> t
val narrow: Cil.ikind -> t -> t -> t
val widen: Cil.ikind -> t -> t -> t
val starting : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val ending : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val of_int: Cil.ikind -> int_t -> t
(** Transform an integer literal to your internal domain representation. *)
val of_bool: Cil.ikind -> bool -> t
(** Transform a known boolean value to the default internal representation. It
* should follow C: [of_bool true = of_int 1] and [of_bool false = of_int 0]. *)
val of_interval: ?suppress_ovwarn:bool -> Cil.ikind -> int_t * int_t -> t
val of_congruence: Cil.ikind -> int_t * int_t -> t
val of_bitfield: Cil.ikind -> int_t * int_t -> t
val to_bitfield: Cil.ikind -> t -> int_t * int_t
val is_top_of: Cil.ikind -> t -> bool
val invariant_ikind : Cil.exp -> Cil.ikind -> t -> Invariant.t
val refine_with_congruence: Cil.ikind -> t -> (int_t * int_t) option -> t
val refine_with_bitfield: Cil.ikind -> t -> (int_t * int_t) -> t
val refine_with_interval: Cil.ikind -> t -> (int_t * int_t) option -> t
val refine_with_excl_list: Cil.ikind -> t -> (int_t list * (int64 * int64)) option -> t
val refine_with_incl_list: Cil.ikind -> t -> int_t list option -> t
val project: Cil.ikind -> PrecisionUtil.int_precision -> t -> t
val arbitrary: Cil.ikind -> t QCheck.arbitrary
end
(** Interface of IntDomain implementations taking an ikind for arithmetic operations *)
module type SOverflow =
sig
include S
val add : ?no_ov:bool -> Cil.ikind -> t -> t -> t * overflow_info
val sub : ?no_ov:bool -> Cil.ikind -> t -> t -> t * overflow_info
val mul : ?no_ov:bool -> Cil.ikind -> t -> t -> t * overflow_info
val div : ?no_ov:bool -> Cil.ikind -> t -> t -> t * overflow_info
val neg : ?no_ov:bool -> Cil.ikind -> t -> t * overflow_info
val cast_to : ?suppress_ovwarn:bool -> ?torg:Cil.typ -> ?no_ov:bool -> Cil.ikind -> t -> t * overflow_info
val of_int : Cil.ikind -> int_t -> t * overflow_info
val of_interval: ?suppress_ovwarn:bool -> Cil.ikind -> int_t * int_t -> t * overflow_info
val starting : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t * overflow_info
val ending : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t * overflow_info
val shift_left : Cil.ikind -> t -> t -> t * overflow_info
val shift_right: Cil.ikind -> t -> t -> t * overflow_info
end
module SOverflowUnlifter (D : SOverflow) : S with type int_t = D.int_t and type t = D.t
module type Y =
sig
include B
include Lattice.Top with type t := t
include Arith with type t:=t
val of_int: Cil.ikind -> int_t -> t
(** Transform an integer literal to your internal domain representation with the specified ikind. *)
val of_bool: Cil.ikind -> bool -> t
(** Transform a known boolean value to the default internal representation of the specified ikind. It
* should follow C: [of_bool true = of_int 1] and [of_bool false = of_int 0]. *)
val of_interval: ?suppress_ovwarn:bool -> Cil.ikind -> int_t * int_t -> t
val of_congruence: Cil.ikind -> int_t * int_t -> t
val of_bitfield: Cil.ikind -> int_t * int_t -> t
val to_bitfield: Cil.ikind -> t -> int_t * int_t
val starting : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val ending : ?suppress_ovwarn:bool -> Cil.ikind -> int_t -> t
val is_top_of: Cil.ikind -> t -> bool
val project: PrecisionUtil.int_precision -> t -> t
val invariant: Cil.exp -> t -> Invariant.t
end
(** The signature of integral value domains keeping track of ikind information *)
module type Z = Y with type int_t = Z.t
module IntDomLifter (I: S): Y with type int_t = I.int_t
module type Ikind =
sig
val ikind: unit -> Cil.ikind
end
module PtrDiffIkind : Ikind
module IntDomWithDefaultIkind (I: Y) (Ik: Ikind) : Y with type t = I.t and type int_t = I.int_t
(* module ManyInts : S *)
(* module IntDomList : S *)
module IntDomTuple : sig
include Z
val no_interval: t -> t
val no_intervalSet: t -> t
val no_bitfield: t -> t
val ikind: t -> ikind
end
val of_const: Z.t * Cil.ikind * string option -> IntDomTuple.t
module Size : sig
(** The biggest type we support for integers. *)
val top_typ : Cil.typ
val range : Cil.ikind -> Z.t * Z.t
val is_cast_injective : from_type:Cil.typ -> to_type:Cil.typ -> bool
val bits : Cil.ikind -> int * int
val cast : Cil.ikind -> Z.t -> Z.t
end
module BISet: SetDomain.S with type elt = Z.t
exception ArithmeticOnIntegerBot of string
exception Unknown
(** An exception that can be raised when the result of a computation is unknown.
* This is caught by lifted domains and will be replaced by top. *)
exception Error
(** An exception that can be raised when an arithmetic error occurs. This is
* caught by lifted domains and the evaluation will then be set to bot, which
* signifies an error in computation *)
exception IncompatibleIKinds of string
(** {b Predefined domains} *)
module Integers(Ints_t : IntOps.IntOps): IkindUnawareS with type t = Ints_t.t and type int_t = Ints_t.t
(** The integers with their natural orderings. Calling [top] and [bot] will
* raise exceptions. *)
module FlatPureIntegers: IkindUnawareS with type t = IntOps.Int64Ops.t and type int_t = IntOps.Int64Ops.t
(** The integers with flattened orderings. Calling [top] and [bot] or [join]ing
or [meet]ing inequal elements will raise exceptions. *)
module Flattened : IkindUnawareS with type t = [`Top | `Lifted of IntOps.Int64Ops.t | `Bot] and type int_t = IntOps.Int64Ops.t
(** This is the typical flattened integer domain used in Kildall's constant
* propagation. *)
module Lifted : IkindUnawareS with type t = [`Top | `Lifted of int64 | `Bot] and type int_t = int64
(** Artificially bounded integers in their natural ordering. *)
module IntervalFunctor(Ints_t : IntOps.IntOps): SOverflow with type int_t = Ints_t.t and type t = (Ints_t.t * Ints_t.t) option
module BitfieldFunctor(Ints_t : IntOps.IntOps): SOverflow with type int_t = Ints_t.t and type t = (Ints_t.t * Ints_t.t)
module IntervalSetFunctor(Ints_t : IntOps.IntOps): SOverflow with type int_t = Ints_t.t and type t = (Ints_t.t * Ints_t.t) list
module Interval32 :Y with (* type t = (IntOps.Int64Ops.t * IntOps.Int64Ops.t) option and *) type int_t = IntOps.Int64Ops.t
module Interval : SOverflow with type int_t = Z.t
module Bitfield : SOverflow with type int_t = Z.t
module IntervalSet : SOverflow with type int_t = Z.t
module Congruence : S with type int_t = Z.t
module DefExc : S with type int_t = Z.t
(** The DefExc domain. The Flattened integer domain is topped by exclusion sets.
* Good for analysing branches. *)
(** {b Domain constructors} *)
module Flat (Base: IkindUnawareS): IkindUnawareS with type t = [ `Bot | `Lifted of Base.t | `Top ] and type int_t = Base.int_t
(** Creates a flat value domain, where all ordering is lost. Arithmetic
* operations are lifted such that only lifted values can be evaluated
* otherwise the top/bot is simply propagated with bot taking precedence over
* top. *)
module Lift (Base: IkindUnawareS): IkindUnawareS with type t = [ `Bot | `Lifted of Base.t | `Top ] and type int_t = Base.int_t
(** Just like {!Value.Flat} except the order is preserved. *)
(* module Interval : S *)
(** Interval domain with int64-s --- use with caution! *)
(* module IncExcInterval : S with type t = [ | `Excluded of Interval.t| `Included of Interval.t ] *)
(** Inclusive and exclusive intervals. Warning: NOT A LATTICE *)
module Enums : S with type int_t = Z.t