@@ -498,40 +498,34 @@ struct
498498 x
499499 else
500500 (* check if one part covers the entire array, so we can drop partitioning *)
501- begin
502- let e_must_bigger_max_index =
503- match length with
504- | Some l ->
505- begin
506- match Idx. to_int l with
507- | Some i ->
508- let b = VDQ. may_be_less ask.eval_int e (Cil. kintegerCilint (Cilfacade. ptrdiff_ikind () ) i) in
509- not b (* !(e <_{may} length) => e >=_{must} length *)
510- | None -> false
511- end
512- | _ -> false
513- in
514- let e_must_less_zero =
501+ let e_must_bigger_max_index = GobOption. exists (fun i ->
502+ let b = VDQ. may_be_less ask.eval_int e (Cil. kintegerCilint (Cilfacade. ptrdiff_ikind () ) i) in
503+ not b (* !(e <_{may} length) => e >=_{must} length *)
504+ ) (Option. bind length Idx. to_int)
505+ in
506+
507+ if e_must_bigger_max_index then
508+ (* Entire array is covered by left part, dropping partitioning. *)
509+ Joint xl
510+ else
511+ let e_must_less_zero =
515512 VDQ. eval_int_binop (module BoolDomain. MustBool ) Lt ask.eval_int e Cil. zero (* TODO: untested *)
516513 in
517- if e_must_bigger_max_index then
518- (* Entire array is covered by left part, dropping partitioning. *)
519- Joint xl
520- else if e_must_less_zero then
514+ if e_must_less_zero then
521515 (* Entire array is covered by right value, dropping partitioning. *)
522516 Joint xr
523517 else
524518 (* If we can not drop partitioning, move *)
525519 move (movement_for_exp e) (e, (xl,xm, xr))
526- end
520+
527521 | _ -> x (* If the array is not partitioned, nothing to do *)
528522
529523 let move_if_affected ?replace_with_const = move_if_affected_with_length ?replace_with_const None
530524
531525 let set_with_length length (ask :VDQ.t ) x (i ,_ ) a =
532526 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;
533527 match i with
534- | Some ie when CilType.Exp. equal ie (Lazy. force Offset.Index.Exp. all) ->
528+ | Some i when CilType.Exp. equal i (Lazy. force Offset.Index.Exp. all) ->
535529 (* TODO: Doesn't seem to work for unassume. *)
536530 Joint a
537531 | Some i when CilType.Exp. equal i (Lazy. force Offset.Index.Exp. any) ->
@@ -547,16 +541,9 @@ struct
547541 let n = ask.eval_int e in
548542 VDQ.ID. to_int n
549543 in
550- let equals_zero e = BatOption. map_default (Z. equal Z. zero) false (exp_value e) in
544+ let equals_zero e = GobOption. exists (Z. equal Z. zero) (exp_value e) in
551545 let equals_maxIndex e =
552- match length with
553- | Some l ->
554- begin
555- match Idx. to_int l with
556- | Some i -> BatOption. map_default (Z. equal (Z. pred i)) false (exp_value e)
557- | None -> false
558- end
559- | _ -> false
546+ GobOption. exists2 (fun l -> Z. equal (Z. pred l)) (Option. bind length Idx. to_int) (exp_value e)
560547 in
561548 let lubIfNotBot x = if Val. is_bot x then x else Val. join a x in
562549 match x with
@@ -663,19 +650,14 @@ struct
663650
664651 let length _ = None
665652
653+ let must_i_one_smaller l i =
654+ GobOption. exists2 (fun l i -> Z. equal i (Z. pred l)) (Option. bind l Idx. to_int) i
655+
656+ let must_be_zero = GobOption. exists (Z. equal Z. zero)
657+
666658 let smart_op (op : Val.t -> Val.t -> Val.t ) length x1 x2 x1_eval_int x2_eval_int =
667659 normalize @@
668- let must_be_length_minus_one v = match length with
669- | Some l ->
670- begin
671- match Idx. to_int l with
672- | Some i ->
673- v = Some (Z. pred i)
674- | None -> false
675- end
676- | None -> false
677- in
678- let must_be_zero v = v = Some Z. zero in
660+ let must_be_length_minus_one = must_i_one_smaller length in
679661 let op_over_all = op (join_of_all_parts x1) (join_of_all_parts x2) in
680662 match x1, x2 with
681663 | Partitioned (e1 , (xl1 , xm1 , xr1 )), Partitioned (e2 , (xl2 , xm2 , xr2 )) when Basetype.CilExp. equal e1 e2 ->
@@ -739,17 +721,7 @@ struct
739721
740722 let smart_leq_with_length length x1_eval_int x2_eval_int x1 x2 =
741723 let leq' = Val. smart_leq x1_eval_int x2_eval_int in
742- let must_be_zero v = (v = Some Z. zero) in
743- let must_be_length_minus_one v = match length with
744- | Some l ->
745- begin
746- match Idx. to_int l with
747- | Some i ->
748- v = Some (Z. pred i)
749- | None -> false
750- end
751- | None -> false
752- in
724+ let must_be_length_minus_one = must_i_one_smaller length in
753725 match x1, x2 with
754726 | Joint x1 , Joint x2 ->
755727 leq' x1 x2
@@ -830,10 +802,10 @@ end
830802(* This is the main array out of bounds check *)
831803let array_oob_check ( type a ) (module Idx: IntDomain.Z with type t = a ) (x , l ) (e , v ) =
832804 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 *)
833- let idx_before_end = Idx. to_bool (Idx. lt v l) (* check whether index is before the end of the array *)
834- and idx_after_start = Idx. to_bool (Idx. ge v (Idx. of_int (Cilfacade. ptrdiff_ikind () ) Z. zero)) in (* check whether the index is non-negative *)
805+ let idx_before_end = Idx. to_bool (Idx. lt v l) in (* check whether index is before the end of the array *)
806+ let idx_after_start = Idx. to_bool (Idx. ge v (Idx. of_int (Cilfacade. ptrdiff_ikind () ) Z. zero)) in (* check whether the index is non-negative *)
835807 (* For an explanation of the warning types check the Pull Request #255 *)
836- match ( idx_after_start, idx_before_end) with
808+ match idx_after_start, idx_before_end with
837809 | Some true , Some true -> (* Certainly in bounds on both sides.*)
838810 ()
839811 | Some true , Some false -> (* The following matching differentiates the must and may cases*)
0 commit comments