-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy patharrayDomain.ml
More file actions
1913 lines (1717 loc) · 87.1 KB
/
arrayDomain.ml
File metadata and controls
1913 lines (1717 loc) · 87.1 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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
open GoblintCil
open Pretty
open GobConfig
open FlagHelper
module M = Messages
module A = Array
module VDQ = ValueDomainQueries
type domain = TrivialDomain | PartitionedDomain | UnrolledDomain
(* determines the domain based on variable, type and flag *)
let get_domain ~varAttr ~typAttr =
let domain_from_string = function
| "partitioned" -> PartitionedDomain
| "trivial" -> TrivialDomain
| "unroll" -> UnrolledDomain
| _ -> failwith "AttributeConfiguredArrayDomain: invalid option for domain"
in
(*TODO add options?*)
(*TODO let attribute determine unrolling factor?*)
let from_attributes = List.find_map (
fun (Attr (s,ps) )->
if s = "goblint_array_domain" then (
List.find_map (fun p -> match p with
| AStr x -> Some x
| _ -> None
) ps
)
else None
) in
if get_bool "annotation.goblint_array_domain" then
match from_attributes varAttr, from_attributes typAttr with
| Some x, _ -> domain_from_string x
| _, Some x -> domain_from_string x
| _ -> domain_from_string @@ get_string "ana.base.arrays.domain"
else domain_from_string @@ get_string "ana.base.arrays.domain"
let can_recover_from_top x = x <> TrivialDomain
module type S0 =
sig
include Lattice.S
type idx
type value
val set: VDQ.t -> t -> Basetype.CilExp.t option * idx -> value -> t
val make: ?varAttr:attributes -> ?typAttr:attributes -> idx -> value -> t
val length: t -> idx option
val move_if_affected: ?replace_with_const:bool -> VDQ.t -> t -> Cil.varinfo -> (Cil.exp -> int option) -> t
val get_vars_in_e: t -> Cil.varinfo list
val map: (value -> value) -> t -> t
val fold_left: ('a -> value -> 'a) -> 'a -> t -> 'a
val smart_join: (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t -> t
val smart_widen: (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t -> t
val smart_leq: (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t -> bool
val update_length: idx -> t -> t
val project: ?varAttr:attributes -> ?typAttr:attributes -> VDQ.t -> t -> t
val invariant: value_invariant:(offset:Cil.offset -> lval:Cil.lval -> value -> Invariant.t) -> offset:Cil.offset -> lval:Cil.lval -> t -> Invariant.t
end
module type S =
sig
include S0
val domain_of_t: t -> domain
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> value
end
module type Str =
sig
include S0
type ret = Null | NotNull | Maybe
type substr = IsNotSubstr | IsSubstrAtIndex0 | IsMaybeSubstr
val get: VDQ.t -> t -> Basetype.CilExp.t option * idx -> ret
val to_null_byte_domain: string -> t
val to_string_length: t -> idx
val string_copy: t -> t -> int option -> t
val string_concat: t -> t -> int option -> t
val substring_extraction: t -> t -> substr
val string_comparison: t -> t -> int option -> idx
end
module type StrWithDomain =
sig
include Str
include S with type t := t and type idx := idx
end
module type LatticeWithInvalidate =
sig
include Lattice.S
val invalidate_abstract_value: t -> t
end
module type LatticeWithSmartOps =
sig
include LatticeWithInvalidate
val smart_join: (Cil.exp -> Z.t option) -> (Cil.exp -> Z.t option) -> t -> t -> t
val smart_widen: (Cil.exp -> Z.t option) -> (Cil.exp -> Z.t option) -> t -> t -> t
val smart_leq: (Cil.exp -> Z.t option) -> (Cil.exp -> Z.t option) -> t -> t -> bool
end
module type Null =
sig
type t
type retnull = Null | NotNull | Maybe
val null: unit -> t
val is_null: t -> retnull
val get_ikind: t -> Cil.ikind option
val zero_of_ikind: Cil.ikind -> t
val not_zero_of_ikind: Cil.ikind -> t
end
module type LatticeWithNull =
sig
include LatticeWithSmartOps
include Null with type t := t
end
module Trivial (Val: LatticeWithInvalidate) (Idx: Lattice.S): S with type value = Val.t and type idx = Idx.t =
struct
include Val
let name () = "trivial arrays"
type idx = Idx.t
type value = Val.t
let domain_of_t _ = TrivialDomain
let show x = "Array: " ^ Val.show x
let pretty () x = text "Array: " ++ pretty () x
let pretty_diff () (x,y) = dprintf "%s: %a not leq %a" (name ()) pretty x pretty y
let get ?(checkBounds=true) (ask: VDQ.t) a i = a
let set (ask: VDQ.t) a (ie, i) v =
match ie with
| Some ie when Offset.Index.Exp.is_all ie ->
v
| _ ->
join a v
let make ?(varAttr=[]) ?(typAttr=[]) i v = v
let length _ = None
let move_if_affected ?(replace_with_const=false) _ x _ _ = x
let get_vars_in_e _ = []
let map f x = f x
let fold_left f a x = f a x
let printXml f x = BatPrintf.fprintf f "<value>\n<map>\n<key>Any</key>\n%a\n</map>\n</value>\n" Val.printXml x
let smart_join _ _ = join
let smart_widen _ _ = widen
let smart_leq _ _ = leq
let update_length _ x = x
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval x =
match offset with
(* invariants for all indices *)
| NoOffset when get_bool "witness.invariant.goblint" ->
let i_lval = Cil.addOffsetLval (Index (Lazy.force Offset.Index.Exp.all, NoOffset)) lval in
value_invariant ~offset ~lval:i_lval x
| NoOffset ->
Invariant.none
(* invariant for one index *)
| Index (i, offset) ->
value_invariant ~offset ~lval x
(* invariant for one field *)
| Field (f, offset) ->
Invariant.none
end
let factor () =
match get_int "ana.base.arrays.unrolling-factor" with
| 0 -> failwith "ArrayDomain: ana.base.arrays.unrolling-factor needs to be set when using the unroll domain"
| x -> x
module Unroll (Val: LatticeWithInvalidate) (Idx:IntDomain.Z): S with type value = Val.t and type idx = Idx.t =
struct
module Factor = struct let x () = (get_int "ana.base.arrays.unrolling-factor") end
module Base = Lattice.ProdList (Val) (Factor)
include Lattice.ProdSimple(Base) (Val)
let name () = "unrolled arrays"
type idx = Idx.t
type value = Val.t
let domain_of_t _ = UnrolledDomain
let join_of_all_parts (xl, xr) = List.fold_left Val.join xr xl
let show (xl, xr) =
let rec show_list xlist = match xlist with
| [] -> " --- "
| hd::tl -> (Val.show hd ^ " - " ^ (show_list tl)) in
"Array (unrolled to " ^ (Stdlib.string_of_int (factor ())) ^ "): " ^
(show_list xl) ^ Val.show xr ^ ")"
let pretty () x = text "Array: " ++ text (show x)
let pretty_diff () (x,y) = dprintf "%s: %a not leq %a" (name ()) pretty x pretty y
let get ?(checkBounds=true) (ask: VDQ.t) (xl, xr) (_,i) =
let search_unrolled_values min_i max_i =
let rec subjoin l i = match l with
| [] -> Val.bot ()
| hd::tl ->
begin
match Z.gt i max_i, Z.lt i min_i with
| false,true -> subjoin tl (Z.succ i)
| false,false -> Val.join hd (subjoin tl (Z.succ i))
| _,_ -> Val.bot ()
end in
subjoin xl Z.zero in
let f = Z.of_int (factor ()) in
let min_i = BatOption.default Z.zero (Idx.minimal i) in
let max_i = BatOption.default f (Idx.maximal i) in
if Z.geq min_i f then xr
else if Z.lt max_i f then search_unrolled_values min_i max_i
else Val.join xr (search_unrolled_values min_i (Z.of_int ((factor ())-1)))
let set (ask: VDQ.t) (xl,xr) (_,i) v =
let update_unrolled_values min_i max_i =
let rec weak_update l i = match l with
| [] -> []
| hd::tl ->
if Z.lt i min_i then hd::(weak_update tl (Z.succ i))
else if Z.gt i max_i then (hd::tl)
else (Val.join hd v)::(weak_update tl (Z.succ i)) in
let rec full_update l i = match l with
| [] -> []
| hd::tl ->
if Z.lt i min_i then hd::(full_update tl (Z.succ i))
else v::tl in
if Z.equal min_i max_i then full_update xl Z.zero
else weak_update xl Z.zero in
let f = Z.of_int (factor ()) in
let min_i = BatOption.default Z.zero (Idx.minimal i) in
let max_i = BatOption.default f (Idx.maximal i) in
if Z.geq min_i f then (xl, (Val.join xr v))
else if Z.lt max_i f then ((update_unrolled_values min_i max_i), xr)
else ((update_unrolled_values min_i (Z.of_int ((factor ())-1))), (Val.join xr v))
let set ask (xl, xr) (ie, i) v =
match ie with
| Some ie when Offset.Index.Exp.is_all ie ->
(* TODO: Doesn't seem to work for unassume because unrolled elements are top-initialized, not bot-initialized. *)
(BatList.make (factor ()) v, v)
| _ ->
set ask (xl, xr) (ie, i) v
let make ?(varAttr=[]) ?(typAttr=[]) _ v =
let xl = BatList.make (factor ()) v in
(xl,Val.bot ())
let length _ = None
let move_if_affected ?(replace_with_const=false) _ x _ _ = x
let get_vars_in_e _ = []
let map f (xl, xr) = ((List.map f xl), f xr)
let fold_left f a x = f a (join_of_all_parts x)
let printXml f (xl,xr) = BatPrintf.fprintf f "<value>\n<map>\n
<key>unrolled array</key>\n
<key>xl</key>\n%a\n\n
<key>xm</key>\n%a\n\n
</map></value>\n" Base.printXml xl Val.printXml xr
let smart_join _ _ = join
let smart_widen _ _ = widen
let smart_leq _ _ = leq
let update_length _ x = x
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval ((xl, xr) as x) =
match offset with
(* invariants for all indices *)
| NoOffset ->
let i_all =
if Val.is_bot xr then
Invariant.top ()
else if get_bool "witness.invariant.goblint" then (
let i_lval = Cil.addOffsetLval (Index (Lazy.force Offset.Index.Exp.all, NoOffset)) lval in
value_invariant ~offset ~lval:i_lval (join_of_all_parts x)
)
else
Invariant.top ()
in
BatList.fold_lefti (fun acc i x ->
let i_lval = Cil.addOffsetLval (Index (Cil.integer i, NoOffset)) lval in
let i = value_invariant ~offset ~lval:i_lval x in
Invariant.(acc && i)
) i_all xl
(* invariant for one index *)
| Index (i, offset) ->
Invariant.none (* TODO: look up *)
(* invariant for one field *)
| Field (f, offset) ->
Invariant.none
end
(** Special signature so that we can use the _with_length functions from PartitionedWithLength but still match the interface *
* defined for array domains *)
module type SPartitioned =
sig
include S
val set_with_length: idx option -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> value -> t
val smart_join_with_length: idx option -> (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t -> t
val smart_widen_with_length: idx option -> (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t-> t
val smart_leq_with_length: idx option -> (exp -> Z.t option) -> (exp -> Z.t option) -> t -> t -> bool
val move_if_affected_with_length: ?replace_with_const:bool -> idx option -> VDQ.t -> t -> Cil.varinfo -> (Cil.exp -> int option) -> t
end
module Partitioned (Val: LatticeWithSmartOps) (Idx:IntDomain.Z): SPartitioned with type value = Val.t and type idx = Idx.t =
struct
include Printable.Std
type t = Joint of Val.t | Partitioned of (CilType.Exp.t * (Val.t * Val.t * Val.t)) [@@deriving eq, ord, hash]
type idx = Idx.t
type value = Val.t
let domain_of_t _ = PartitionedDomain
let name () = "partitioned array"
let relift = function
| Joint v -> Joint (Val.relift v)
| Partitioned (e, (l, m, r)) -> Partitioned (CilType.Exp.relift e, (Val.relift l, Val.relift m, Val.relift r))
let join_of_all_parts = function
| Joint v -> v
| Partitioned (e, (xl, xm, xr)) -> Val.join xl (Val.join xm xr)
(** Ensures an array where all three Val are equal, is represented by an unpartitioned array *)
let normalize = function
| Joint v -> Joint v
| (Partitioned (e, (xl, xm, xr)) as p) ->
if Val.equal xl xm && Val.equal xm xr then Joint xl
else p
let leq (x:t) (y:t) =
match x, y with
| Joint x, Joint y -> Val.leq x y
| Partitioned (e,(xl, xm, xr)), Joint y -> Val.leq xl y && Val.leq xm y && Val.leq xr y
| Partitioned (e,(xl, xm, xr)), Partitioned (e',(yl, ym, yr)) ->
CilType.Exp.equal e e' && Val.leq xl yl && Val.leq xm ym && Val.leq xr yr
| Joint x, Partitioned (e, (xl, xm, xr)) -> Val.leq x xl && Val.leq x xm && Val.leq x xr
let bot () = Joint (Val.bot ())
let is_bot (x:t) = Val.is_bot (join_of_all_parts x)
let top () = Joint (Val.top ())
let is_top = function
| Joint x -> Val.is_top x
| _-> false
let join (x:t) (y:t) = normalize @@
match x, y with
| Joint x, Joint y -> Joint (Val.join x y)
| Partitioned (e,(xl, xm, xr)), Joint y -> Partitioned (e,(Val.join xl y, Val.join xm y, Val.join xr y))
| Joint x, Partitioned (e,(yl, ym, yr)) -> Partitioned (e,(Val.join x yl, Val.join x ym, Val.join x yr))
| Partitioned (e,(xl, xm, xr)), Partitioned (e',(yl, ym, yr)) ->
if CilType.Exp.equal e e' then Partitioned (e,(Val.join xl yl, Val.join xm ym, Val.join xr yr))
else Joint (Val.join (join_of_all_parts x) (join_of_all_parts y))
let widen (x:t) (y:t) = normalize @@ match x,y with
| Joint x, Joint y -> Joint (Val.widen x y)
| Partitioned (e,(xl, xm, xr)), Joint y -> Partitioned (e,(Val.widen xl y, Val.widen xm y, Val.widen xr y))
| Joint x, Partitioned (e,(yl, ym, yr)) -> Partitioned (e,(Val.widen x yl, Val.widen x ym, Val.widen x yr))
| Partitioned (e,(xl, xm, xr)), Partitioned (e',(yl, ym, yr)) ->
if CilType.Exp.equal e e' then Partitioned (e,(Val.widen xl yl, Val.widen xm ym, Val.widen xr yr))
else Joint (Val.widen (join_of_all_parts x) (join_of_all_parts y))
let show = function
| Joint x -> "Array (no part.): " ^ Val.show x
| Partitioned (e,(xl, xm, xr)) ->
"Array (part. by " ^ CilType.Exp.show e ^ "): (" ^
Val.show xl ^ " -- " ^
Val.show xm ^ " -- " ^
Val.show xr ^ ")"
let pretty () x = text "Array: " ++ text (show x)
let pretty_diff () (x,y) = dprintf "%s: %a not leq %a" (name ()) pretty x pretty y
let printXml f = function
| Joint x -> BatPrintf.fprintf f "<value>\n<map>\n<key>Any</key>\n%a\n</map>\n</value>\n" Val.printXml x
| Partitioned (e,(xl, xm, xr)) ->
BatPrintf.fprintf f "<value>\n<map>\n
<key>Partitioned By</key>\n%a\n
<key>l</key>\n%a\n\n
<key>m</key>\n%a\n\n
<key>r</key>\n%a\n\n
</map></value>\n" CilType.Exp.printXml e Val.printXml xl Val.printXml xm Val.printXml xr
let to_yojson = function
| Joint x -> `Assoc [ ("any", Val.to_yojson x) ]
| Partitioned (e,(xl, xm, xr)) ->
`Assoc [ ("partitioned_by", CilType.Exp.to_yojson e);
("l", Val.to_yojson xl);
("m", Val.to_yojson xm);
("r", Val.to_yojson xr) ]
let get ?(checkBounds=true) (ask:VDQ.t) (x:t) (i,_) =
match x, i with
| Joint v, _ -> v
| Partitioned (e, (xl, xm, xr)), Some i' ->
begin
if VDQ.must_be_equal ask.eval_int e i' then xm
else
begin
let contributionLess = match VDQ.may_be_less ask.eval_int i' e with (* (may i < e) ? xl : bot *)
| false -> Val.bot ()
| _ -> xl in
let contributionEqual = match VDQ.may_be_equal ask.eval_int i' e with (* (may i = e) ? xm : bot *)
| false -> Val.bot ()
| _ -> xm in
let contributionGreater = match VDQ.may_be_less ask.eval_int e i' with (* (may i > e) ? xr : bot *)
| false -> Val.bot ()
| _ -> xr in
Val.join (Val.join contributionLess contributionEqual) contributionGreater
end
end
| _ -> join_of_all_parts x
let get_vars_in_e = function
| Partitioned (e, _) -> Basetype.CilExp.get_vars e
| _ -> []
(* expressions containing globals or array accesses are not suitable for partitioning *)
let not_allowed_for_part e =
let rec contains_array_access e =
let rec offset_contains_array_access offs =
match offs with
| NoOffset -> false
| Index _ -> true
| Field (_, o) -> offset_contains_array_access o
in
match e with
| Const _
| SizeOf _
| SizeOfE _
| SizeOfStr _
| AlignOf _
| AlignOfE _ -> false
| Question(e1, e2, e3, _) ->
contains_array_access e1 || contains_array_access e2 || contains_array_access e3
| CastE(_, _, e)
| UnOp(_, e , _)
| Real e
| Imag e -> contains_array_access e
| BinOp(_, e1, e2, _) -> contains_array_access e1 || contains_array_access e2
| AddrOf _
| AddrOfLabel _
| StartOf _ -> false
| Lval(Mem e, o) -> offset_contains_array_access o || contains_array_access e
| Lval(Var _, o) -> offset_contains_array_access o
in
let vars = Basetype.CilExp.get_vars e in
List.exists (fun x -> x.vglob) vars || contains_array_access e
let map f = function
| Joint v -> Joint (f v)
| Partitioned (e,(xl, xm, xr)) -> normalize @@ Partitioned (e,(f xl, f xm, f xr))
let fold_left f a = function
| Joint x -> f a x
| Partitioned (_, (xl,xm,xr)) -> f (f (f a xl) xm) xr
let move_if_affected_with_length ?(replace_with_const=false) length (ask:VDQ.t) x (v:varinfo) (movement_for_exp: exp -> int option) =
normalize @@
let move (i:int option) (e, (xl,xm, xr)) =
match i with
| Some 0 ->
Partitioned (e, (xl, xm, xr))
| Some 1 ->
Partitioned (e, (Val.join xl xm, xr, xr)) (* moved one to the right *)
| Some -1 ->
Partitioned (e, (xl, xl, Val.join xm xr)) (* moved one to the left *)
| Some x when x > 1 ->
Partitioned (e, (Val.join (Val.join xl xm) xr, xr, xr)) (* moved more than one to the right *)
| Some x when x < -1 ->
Partitioned (e, (xl, xl, Val.join (Val.join xl xm) xr)) (* moved more than one to the left *)
| _ ->
begin
let nval = join_of_all_parts x in
let default = Joint nval in
if replace_with_const then
let n = ask.eval_int e in
match VDQ.ID.to_int n with
| Some i ->
Partitioned ((Cil.kintegerCilint (Cilfacade.ptrdiff_ikind ()) i), (xl, xm, xr))
| _ -> default
else
default
end
in
match x with
| Partitioned (e, (xl,xm, xr)) ->
let is_affected = Basetype.CilExp.occurs v e in
if not is_affected then
x
else
(* check if one part covers the entire array, so we can drop partitioning *)
let e_must_bigger_max_index = GobOption.exists (fun i ->
let b = VDQ.may_be_less ask.eval_int e (Cil.kintegerCilint (Cilfacade.ptrdiff_ikind ()) i) in
not b (* !(e <_{may} length) => e >=_{must} length *)
) (Option.bind length Idx.to_int)
in
if e_must_bigger_max_index then
(* Entire array is covered by left part, dropping partitioning. *)
Joint xl
else
let e_must_less_zero =
VDQ.eval_int_binop (module BoolDomain.MustBool) Lt ask.eval_int e Cil.zero (* TODO: untested *)
in
if e_must_less_zero then
(* Entire array is covered by right value, dropping partitioning. *)
Joint xr
else
(* If we can not drop partitioning, move *)
move (movement_for_exp e) (e, (xl,xm, xr))
| _ -> x (* If the array is not partitioned, nothing to do *)
let move_if_affected ?replace_with_const = move_if_affected_with_length ?replace_with_const None
let set_with_length length (ask:VDQ.t) x (i,_) a =
if M.tracing then M.trace "update_offset" "part array set_with_length %a %s %a" pretty x (BatOption.map_default Basetype.CilExp.show "None" i) Val.pretty a;
match i with
| Some i when Offset.Index.Exp.is_all i ->
(* TODO: Doesn't seem to work for unassume. *)
Joint a
| Some i when Offset.Index.Exp.is_any i ->
(assert !AnalysisState.global_initialization; (* just joining with xm here assumes that all values will be set, which is guaranteed during inits *)
(* the join is needed here! see e.g 30/04 *)
let o = match x with Partitioned (_, (_, xm, _)) -> xm | Joint v -> v in
let r = Val.join o a in
Joint r)
| _ ->
normalize @@
let use_last = get_string "ana.base.partition-arrays.keep-expr" = "last" in
let exp_value e =
let n = ask.eval_int e in
VDQ.ID.to_int n
in
(* TODO: use ID.equal_to here, VDQ.ID doesn't have though *)
let equals_zero e = GobOption.exists (Z.equal Z.zero) (exp_value e) in
let equals_maxIndex e =
GobOption.exists2 (fun l -> Z.equal (Z.pred l)) (Option.bind length Idx.to_int) (exp_value e)
in
let lubIfNotBot x = if Val.is_bot x then x else Val.join a x in
match x with
| Joint v ->
(match i with
| Some i when not @@ not_allowed_for_part i ->
let l = if equals_zero i then Val.bot () else join_of_all_parts x in
let r = if equals_maxIndex i then Val.bot () else join_of_all_parts x in
Partitioned (i, (l, a, r))
| _ -> Joint (Val.join v a)
)
| Partitioned (e, (xl, xm, xr)) ->
let isEqual = VDQ.must_be_equal ask.eval_int in
match i with
| Some i' when not use_last || not_allowed_for_part i' -> begin
let default =
let left =
match VDQ.may_be_less ask.eval_int i' e with (* (may i < e) ? xl : bot *) (* TODO: untested *)
| false -> xl
| _ -> lubIfNotBot xl in
let middle =
match VDQ.may_be_equal ask.eval_int i' e with (* (may i = e) ? xm : bot *)
| false -> xm
| _ -> Val.join xm a in
let right =
match VDQ.may_be_less ask.eval_int e i' with (* (may i > e) ? xr : bot *) (* TODO: untested *)
| false -> xr
| _ -> lubIfNotBot xr in
Partitioned (e, (left, middle, right))
in
if isEqual e i' then
(* e = _{must} i => update strongly *)
Partitioned (e, (xl, a, xr))
else if Cil.isConstant e && Cil.isConstant i' then
match Cil.getInteger e, Cil.getInteger i' with
| Some (e'': Cilint.cilint), Some i'' ->
if Z.equal i'' (Z.succ e'') then
(* If both are integer constants and they are directly adjacent, we change partitioning to maintain information *)
Partitioned (i', (Val.join xl xm, a, xr))
else if Z.equal e'' (Z.succ i'') then
Partitioned (i', (xl, a, Val.join xm xr))
else
default
| _ ->
default
else
default
end
| Some i' ->
if isEqual e i' then
Partitioned (e, (xl, a, xr))
else
let left = if equals_zero i' then Val.bot () else Val.join xl @@ Val.join
(match VDQ.may_be_equal ask.eval_int e i' with (* TODO: untested *)
| false -> Val.bot()
| _ -> xm) (* if e' may be equal to i', but e' may not be smaller than i' then we only need xm *)
(
let t = Cilfacade.typeOf e in
let ik = Cilfacade.get_ikind t in
match VDQ.must_be_equal ask.eval_int (BinOp(PlusA, e, Cil.kinteger ik 1, t)) i' with
| true -> xm
| _ ->
begin
match VDQ.may_be_less ask.eval_int e i' with (* TODO: untested *)
| false-> Val.bot()
| _ -> Val.join xm xr (* if e' may be less than i' then we also need xm for sure *)
end
)
in
let right = if equals_maxIndex i' then Val.bot () else Val.join xr @@ Val.join
(match VDQ.may_be_equal ask.eval_int e i' with (* TODO: untested *)
| false -> Val.bot()
| _ -> xm)
(
let t = Cilfacade.typeOf e in
let ik = Cilfacade.get_ikind t in
match VDQ.must_be_equal ask.eval_int (BinOp(PlusA, e, Cil.kinteger ik (-1), t)) i' with (* TODO: untested *)
| true -> xm
| _ ->
begin
match VDQ.may_be_less ask.eval_int i' e with (* TODO: untested *)
| false -> Val.bot()
| _ -> Val.join xl xm (* if e' may be less than i' then we also need xm for sure *)
end
)
in
(* The new thing is partitioned according to i so we can strongly update *)
Partitioned (i',(left, a, right))
| _ ->
(* If the expression used to write is not known, all segments except the empty ones will be affected *)
Partitioned (e, (lubIfNotBot xl, Val.join xm a, lubIfNotBot xr))
let set = set_with_length None
let make ?(varAttr=[]) ?(typAttr=[]) i v:t =
if Idx.to_int i = Some Z.one then
Partitioned ((Cil.integer 0), (v, v, v))
else if Val.is_bot v then
Joint (Val.bot ())
else
Joint v
let length _ = None
let must_i_one_smaller l i =
GobOption.exists2 (fun l i -> Z.equal i (Z.pred l)) (Option.bind l Idx.to_int) i
let must_be_zero = GobOption.exists (Z.equal Z.zero)
let smart_op (op: Val.t -> Val.t -> Val.t) length x1 x2 x1_eval_int x2_eval_int =
normalize @@
let must_be_length_minus_one = must_i_one_smaller length in
let op_over_all = op (join_of_all_parts x1) (join_of_all_parts x2) in
match x1, x2 with
| Partitioned (e1, (xl1, xm1, xr1)), Partitioned (e2, (xl2, xm2, xr2)) when Basetype.CilExp.equal e1 e2 ->
Partitioned (e1, (op xl1 xl2, op xm1 xm2, op xr1 xr2))
| Partitioned (e1, (xl1, xm1, xr1)), Partitioned (e2, (xl2, xm2, xr2)) ->
if get_string "ana.base.partition-arrays.keep-expr" = "last" || get_bool "ana.base.partition-arrays.smart-join" then
let op = Val.join in (* widen between different components isn't called validly *)
let over_all_x1 = op (op xl1 xm1) xr1 in
let over_all_x2 = op (op xl2 xm2) xr2 in
let e1_in_state_of_x2 = x2_eval_int e1 in
let e2_in_state_of_x1 = x1_eval_int e2 in
(* TODO: why does this depend on exp comparison? probably to use "simpler" expression according to constructor order in compare *)
(* It is mostly SOME order to ensure commutativity of join *)
let e1_is_better = (not (Cil.isConstant e1) && Cil.isConstant e2) || Basetype.CilExp.compare e1 e2 < 0 in
if e1_is_better then (* first try if the result can be partitioned by e1e *)
if must_be_zero e1_in_state_of_x2 then
Partitioned (e1, (xl1, op xm1 over_all_x2, op xr1 over_all_x2))
else if must_be_length_minus_one e1_in_state_of_x2 then
Partitioned (e1, (op xl1 over_all_x2, op xm1 over_all_x2, xr1))
else if must_be_zero e2_in_state_of_x1 then
Partitioned (e2, (xl2, op over_all_x1 xm2, op over_all_x1 xr2))
else if must_be_length_minus_one e2_in_state_of_x1 then
Partitioned (e2, (op over_all_x1 xl2, op over_all_x1 xm2, xr2))
else
Joint op_over_all
else (* first try if the result can be partitioned by e2e *)
if must_be_zero e2_in_state_of_x1 then
Partitioned (e2, (xl2, op over_all_x1 xm2, op over_all_x1 xr2))
else if must_be_length_minus_one e2_in_state_of_x1 then
Partitioned (e2, (op over_all_x1 xl2, op over_all_x1 xm2, xr2))
else if must_be_zero e1_in_state_of_x2 then
Partitioned (e1, (xl1, op xm1 over_all_x2, op xr1 over_all_x2))
else if must_be_length_minus_one e1_in_state_of_x2 then
Partitioned (e1, (op xl1 over_all_x2, op xm1 over_all_x2, xr1))
else
Joint op_over_all
else
Joint op_over_all
| Joint _, Joint _ ->
Joint op_over_all
| Joint x1, Partitioned (e2, (xl2, xm2, xr2)) ->
if must_be_zero (x1_eval_int e2) then
Partitioned (e2, (xl2, op x1 xm2, op x1 xr2))
else if must_be_length_minus_one (x1_eval_int e2) then
Partitioned (e2, (op x1 xl2, op x1 xm2, xr2))
else
Joint op_over_all
| Partitioned (e1, (xl1, xm1, xr1)), Joint x2 ->
if must_be_zero (x2_eval_int e1) then
Partitioned (e1, (xl1, op xm1 x2, op xr1 x2))
else if must_be_length_minus_one (x2_eval_int e1) then
Partitioned (e1, (op xl1 x2, op xm1 x2, xr1))
else
Joint op_over_all
let smart_join_with_length length x1_eval_int x2_eval_int x1 x2 =
smart_op (Val.smart_join x1_eval_int x2_eval_int) length x1 x2 x1_eval_int x2_eval_int
let smart_widen_with_length length x1_eval_int x2_eval_int x1 x2 =
smart_op (Val.smart_widen x1_eval_int x2_eval_int) length x1 x2 x1_eval_int x2_eval_int
let smart_leq_with_length length x1_eval_int x2_eval_int x1 x2 =
let leq' = Val.smart_leq x1_eval_int x2_eval_int in
let must_be_length_minus_one = must_i_one_smaller length in
match x1, x2 with
| Joint x1, Joint x2 ->
leq' x1 x2
| Partitioned (e1, (xl1, xm1, xr1)), Joint x2 ->
(* leq' (Val.join xl1 (Val.join xm1 xr1)) (Val.join xl2 (Val.join xm2 xr2)) *)
leq' xl1 x2 && leq' xm1 x2 && leq' xr1 x2
| Partitioned (e1, (xl1, xm1, xr1)), Partitioned (e2, (xl2, xm2, xr2)) ->
if Basetype.CilExp.equal e1 e2 then
leq' xl1 xl2 && leq' xm1 xm2 && leq' xr1 xr2
else if must_be_zero (x1_eval_int e2) then
(* A read will never be from xl2 -> we can ignore that here *)
let l = join_of_all_parts x1 in
leq' l xm2 && leq' l xr2
else if must_be_length_minus_one (x1_eval_int e2) then
(* A read will never be from xr2 -> we can ignore that here *)
let l = join_of_all_parts x1 in
leq' l xl2 && leq' l xm2
else
false
| Joint x1, Partitioned (e2, (xl2, xm2, xr2)) ->
if must_be_zero (x1_eval_int e2) then
leq' x1 xm2 && leq' x1 xr2
else if must_be_length_minus_one (x1_eval_int e2) then
leq' x1 xl2 && leq' x1 xm2
else
leq' x1 xl2 && leq' x1 xr2 && leq' x1 xm2 && leq' x1 xr2
let smart_join = smart_join_with_length None
let smart_widen = smart_widen_with_length None
let smart_leq = smart_leq_with_length None
let meet x y = normalize @@ match x,y with
| Joint x, Joint y -> Joint (Val.meet x y)
| Joint x, Partitioned (e, (xl, xm, xr))
| Partitioned (e, (xl, xm, xr)), Joint x ->
Partitioned (e, (Val.meet x xl, Val.meet x xm, Val.meet x xr))
| Partitioned (e1, (xl1, xm1, xr1)), Partitioned (e2, (xl2, xm2, xr2)) ->
if Basetype.CilExp.equal e1 e2 then
Partitioned (e1, (Val.meet xl1 xl2, Val.meet xm1 xm2, Val.meet xr1 xr2))
else
(* partitioned according to two different expressions -> meet can not be element-wise *)
(* arrays can not be partitioned according to multiple expressions, arbitrary prefer the first one here *)
(* TODO: do smart things if the relationship between e1e and e2e is known *)
x
let narrow x y = normalize @@ match x,y with
| Joint x, Joint y -> Joint (Val.narrow x y)
| Joint x, Partitioned (e, (xl, xm, xr))
| Partitioned (e, (xl, xm, xr)), Joint x ->
Partitioned (e, (Val.narrow x xl, Val.narrow x xm, Val.narrow x xr))
| Partitioned (e1, (xl1, xm1, xr1)), Partitioned (e2, (xl2, xm2, xr2)) ->
if Basetype.CilExp.equal e1 e2 then
Partitioned (e1, (Val.narrow xl1 xl2, Val.narrow xm1 xm2, Val.narrow xr1 xr2))
else
(* partitioned according to two different expressions -> narrow can not be element-wise *)
(* arrays can not be partitioned according to multiple expressions, arbitrary prefer the first one here *)
x
let update_length _ x = x
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval x =
match offset with
(* invariants for all indices *)
| NoOffset when get_bool "witness.invariant.goblint" ->
let i_lval = Cil.addOffsetLval (Index (Lazy.force Offset.Index.Exp.all, NoOffset)) lval in
value_invariant ~offset ~lval:i_lval (join_of_all_parts x)
| NoOffset ->
Invariant.none
(* invariant for one index *)
| Index (i, offset) ->
Invariant.none (* TODO: look up *)
(* invariant for one field *)
| Field (f, offset) ->
Invariant.none
end
(* This is the main array out of bounds check *)
let array_oob_check ( type a ) (module Idx: IntDomain.Z with type t = a) (x, l) (e, v) =
if !AnalysisState.executing_speculative_computations then
()
else if GobConfig.get_bool "ana.arrayoob" then (* The purpose of the following 2 lines is to give the user extra info about the array oob *)
let idx_before_end = Idx.lt v l in (* check whether index is before the end of the array *)
let idx_after_start = Idx.ge v (Idx.of_int (Cilfacade.ptrdiff_ikind ()) Z.zero) in (* check whether the index is non-negative *)
(* For an explanation of the warning types check the Pull Request #255 *)
match idx_after_start, idx_before_end with
| Some true, Some true -> (* Certainly in bounds on both sides.*)
Checks.safe Checks.Category.InvalidMemoryAccess
| Some true, Some false -> (* The following matching differentiates the must and may cases*)
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.error ~category:M.Category.Behavior.Undefined.ArrayOutOfBounds.past_end "Must access array past end";
Checks.error Checks.Category.InvalidMemoryAccess "Invalid array access: Must access past end"
| Some true, None ->
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.warn ~category:M.Category.Behavior.Undefined.ArrayOutOfBounds.past_end "May access array past end";
Checks.warn Checks.Category.InvalidMemoryAccess "Invalid array access: May access past end"
| Some false, Some true ->
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.error ~category:M.Category.Behavior.Undefined.ArrayOutOfBounds.before_start "Must access array before start";
Checks.error Checks.Category.InvalidMemoryAccess "Invalid array access: Must access before start"
| None, Some true ->
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.warn ~category:M.Category.Behavior.Undefined.ArrayOutOfBounds.before_start "May access array before start";
Checks.warn Checks.Category.InvalidMemoryAccess "Invalid array access: May access before start"
| _ ->
AnalysisStateUtil.set_mem_safety_flag InvalidDeref;
M.warn ~category:M.Category.Behavior.Undefined.ArrayOutOfBounds.unknown "May access array out of bounds";
Checks.warn Checks.Category.InvalidMemoryAccess "Invalid array access: May access out of bounds"
module TrivialWithLength (Val: LatticeWithInvalidate) (Idx: IntDomain.Z): S with type value = Val.t and type idx = Idx.t =
struct
module Base = Trivial (Val) (Idx)
include Lattice.Prod (Base) (Idx)
type idx = Idx.t
type value = Val.t
let domain_of_t _ = TrivialDomain
let get ?(checkBounds=true) (ask : VDQ.t) (x, (l : idx)) (e, v) =
if checkBounds then (array_oob_check (module Idx) (x, l) (e, v));
Base.get ask x (e, v)
let set (ask: VDQ.t) (x,l) i v = Base.set ask x i v, l
let make ?(varAttr=[]) ?(typAttr=[]) l x = Base.make l x, l
let length (_,l) = Some l
let move_if_affected ?(replace_with_const=false) _ x _ _ = x
let map f (x, l):t = (Base.map f x, l)
let fold_left f a (x, l) = Base.fold_left f a x
let get_vars_in_e _ = []
let smart_join _ _ = join
let smart_widen _ _ = widen
let smart_leq _ _ = leq
(* It is not necessary to do a least-upper bound between the old and the new length here. *)
(* Any array can only be declared in one location. The value for newl that we get there is *)
(* the one obtained by abstractly evaluating the size expression at this location for the *)
(* current state. If newl leq l this means that we somehow know more about the expression *)
(* determining the size now (e.g. because of narrowing), but this holds for all the times *)
(* the declaration is visited. *)
let update_length newl (x, l) = (x, newl)
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval (x, _) =
Base.invariant ~value_invariant ~offset ~lval x
let printXml f (x,y) =
BatPrintf.fprintf f "<value>\n<map>\n<key>\n%s\n</key>\n%a<key>\n%s\n</key>\n%a</map>\n</value>\n" (XmlUtil.escape (Base.name ())) Base.printXml x "length" Idx.printXml y
let to_yojson (x, y) = `Assoc [ (Base.name (), Base.to_yojson x); ("length", Idx.to_yojson y) ]
end
module PartitionedWithLength (Val: LatticeWithSmartOps) (Idx: IntDomain.Z): S with type value = Val.t and type idx = Idx.t =
struct
module Base = Partitioned (Val) (Idx)
include Lattice.Prod (Base) (Idx)
type idx = Idx.t
type value = Val.t
let domain_of_t _ = PartitionedDomain
let get ?(checkBounds=true) (ask : VDQ.t) (x, (l : idx)) (e, v) =
if checkBounds then (array_oob_check (module Idx) (x, l) (e, v));
Base.get ask x (e, v)
let set ask (x,l) i v = Base.set_with_length (Some l) ask x i v, l
let make ?(varAttr=[]) ?(typAttr=[]) l x = Base.make l x, l
let length (_,l) = Some l
let move_if_affected ?replace_with_const ask (x,l) v i =
(Base.move_if_affected_with_length ?replace_with_const (Some l) ask x v i), l
let map f (x, l):t = (Base.map f x, l)
let fold_left f a (x, l) = Base.fold_left f a x
let get_vars_in_e (x, _) = Base.get_vars_in_e x
let smart_join x_eval_int y_eval_int (x,xl) (y,yl) =
let l = Idx.join xl yl in
(Base.smart_join_with_length (Some l) x_eval_int y_eval_int x y , l)
let smart_widen x_eval_int y_eval_int (x,xl) (y,yl) =
let l = Idx.join xl yl in
(Base.smart_widen_with_length (Some l) x_eval_int y_eval_int x y, l)
let smart_leq x_eval_int y_eval_int (x,xl) (y,yl) =
let l = Idx.join xl yl in
Idx.leq xl yl && Base.smart_leq_with_length (Some l) x_eval_int y_eval_int x y
(* It is not necessary to do a least-upper bound between the old and the new length here. *)
(* Any array can only be declared in one location. The value for newl that we get there is *)
(* the one obtained by abstractly evaluating the size expression at this location for the *)
(* current state. If newl leq l this means that we somehow know more about the expression *)
(* determining the size now (e.g. because of narrowing), but this holds for all the times *)
(* the declaration is visited. *)
let update_length newl (x, l) = (x, newl)
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval (x, _) =
Base.invariant ~value_invariant ~offset ~lval x
let printXml f (x,y) =
BatPrintf.fprintf f "<value>\n<map>\n<key>\n%s\n</key>\n%a<key>\n%s\n</key>\n%a</map>\n</value>\n" (XmlUtil.escape (Base.name ())) Base.printXml x "length" Idx.printXml y
let to_yojson (x, y) = `Assoc [ (Base.name (), Base.to_yojson x); ("length", Idx.to_yojson y) ]
end
module UnrollWithLength (Val: LatticeWithInvalidate) (Idx: IntDomain.Z): S with type value = Val.t and type idx = Idx.t =
struct
module Base = Unroll (Val) (Idx)
include Lattice.Prod (Base) (Idx)
type idx = Idx.t
type value = Val.t
let domain_of_t _ = UnrolledDomain
let get ?(checkBounds=true) (ask : VDQ.t) (x, (l : idx)) (e, v) =
if checkBounds then (array_oob_check (module Idx) (x, l) (e, v));
Base.get ask x (e, v)
let set (ask: VDQ.t) (x,l) i v = Base.set ask x i v, l
let make ?(varAttr=[]) ?(typAttr=[]) l x = Base.make l x, l
let length (_,l) = Some l
let move_if_affected ?(replace_with_const=false) _ x _ _ = x
let map f (x, l):t = (Base.map f x, l)
let fold_left f a (x, l) = Base.fold_left f a x
let get_vars_in_e _ = []
let smart_join _ _ = join
let smart_widen _ _ = widen
let smart_leq _ _ = leq
(* It is not necessary to do a least-upper bound between the old and the new length here. *)
(* Any array can only be declared in one location. The value for newl that we get there is *)
(* the one obtained by abstractly evaluating the size expression at this location for the *)
(* current state. If newl leq l this means that we somehow know more about the expression *)
(* determining the size now (e.g. because of narrowing), but this holds for all the times *)
(* the declaration is visited. *)
let update_length newl (x, l) = (x, newl)
let project ?(varAttr=[]) ?(typAttr=[]) _ t = t
let invariant ~value_invariant ~offset ~lval (x, _) =
Base.invariant ~value_invariant ~offset ~lval x
let printXml f (x,y) =
BatPrintf.fprintf f "<value>\n<map>\n<key>\n%s\n</key>\n%a<key>\n%s\n</key>\n%a</map>\n</value>\n" (XmlUtil.escape (Base.name ())) Base.printXml x "length" Idx.printXml y
let to_yojson (x, y) = `Assoc [ (Base.name (), Base.to_yojson x); ("length", Idx.to_yojson y) ]
end
module NullByte (Val: LatticeWithNull) (Idx: IntDomain.Z): Str with type value = Val.t and type idx = Idx.t =
struct
module MustSet = NullByteSet.MustSet
module MaySet = NullByteSet.MaySet
module Nulls = NullByteSet.MustMaySet
let (<.) = Z.lt
let (<=.) = Z.leq
let (>.) = Z.gt
let (>=.) = Z.geq
let (=.) = Z.equal
let (+.) = Z.add
(* (Must Null Set, May Null Set, Array Size) *)
include Lattice.Prod (Nulls) (struct include Idx let name () = "length" end)
let name () = "ArrayNullBytes"
type idx = Idx.t
type value = Val.t
type ret = Null | NotNull | Maybe
type substr = IsNotSubstr | IsSubstrAtIndex0 | IsMaybeSubstr