Skip to content

Commit 8ae3d89

Browse files
committed
Use speculative comp wrapper instead of threading checkbounds through funs
1 parent ee6ba07 commit 8ae3d89

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

src/analyses/base.ml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,18 +523,18 @@ struct
523523
CPA.find x st.cpa
524524
end
525525

526-
let rec get_mval ~man ?(full=false) ?(checkBounds=true) (st: store) ((x, offs): Addr.Mval.t) (exp:exp option) =
526+
let rec get_mval ~man ?(full=false) (st: store) ((x, offs): Addr.Mval.t) (exp:exp option) =
527527
(* get hold of the variable value, either from local or global state *)
528528
let var = get_var ~man st x in
529-
let v = VD.eval_offset ~checkBounds (Queries.to_value_domain_ask (Analyses.ask_of_man man)) (fun x -> get ~man st x exp) var offs exp (Some (Var x, Offs.to_cil_offset offs)) x.vtype in
529+
let v = VD.eval_offset (Queries.to_value_domain_ask (Analyses.ask_of_man man)) (fun x -> get ~man st x exp) var offs exp (Some (Var x, Offs.to_cil_offset offs)) x.vtype in
530530
if M.tracing then M.tracec "get" "var = %a, %a = %a" VD.pretty var AD.pretty (AD.of_mval (x, offs)) VD.pretty v;
531531
if full then var else match v with
532532
| Blob (c,s,_) -> c
533533
| x -> x
534534

535-
and get_addr ~man ?(top=VD.top ()) ?full ?(checkBounds=true) (st: store) (addr: Addr.t) (exp:exp option) =
535+
and get_addr ~man ?(top=VD.top ()) ?full (st: store) (addr: Addr.t) (exp:exp option) =
536536
match addr with
537-
| Addr.Addr mval -> get_mval ~man ?full ~checkBounds st mval exp
537+
| Addr.Addr mval -> get_mval ~man ?full st mval exp
538538
| Addr.NullPtr ->
539539
begin match get_string "sem.null-pointer.dereference" with
540540
| "assume_none" -> VD.bot ()
@@ -603,7 +603,7 @@ struct
603603
| Union (f,e) -> reachable_from_value ask e t description
604604
(* For arrays, we ask to read from an unknown index, this will cause it
605605
* join all its values. *)
606-
| Array a -> reachable_from_value ask (ValueDomain.CArrays.get ~checkBounds:false (Queries.to_value_domain_ask ask) a (None, ValueDomain.ArrIdxDomain.top ())) t description
606+
| Array a -> reachable_from_value ask (ValueDomain.CArrays.get (Queries.to_value_domain_ask ask) a (None, ValueDomain.ArrIdxDomain.top ())) t description
607607
| Blob (e,_,_) -> reachable_from_value ask e t description
608608
| Struct s -> ValueDomain.Structs.fold (fun k v acc -> AD.join (reachable_from_value ask v t description) acc) s empty
609609
| Int _ -> empty
@@ -613,12 +613,17 @@ struct
613613
| JmpBuf _ -> empty (* Jump buffers are abstract and nothing known can be reached from them *)
614614
| Mutex -> empty (* mutexes are abstract and nothing known can be reached from them *)
615615

616+
let reachable_from_value ask (value: value) (t: typ) (description: string) =
617+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
618+
reachable_from_value ask value t description
619+
616620
(* Get the list of addresses accessible immediately from a given address, thus
617621
* all pointers within a structure should be considered, but we don't follow
618622
* pointers. We return a flattend representation, thus simply an address (set). *)
619623
let reachable_from_addr ~man st (addr: Addr.t): address =
624+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
620625
if M.tracing then M.tracei "reachability" "Checking for %a" Addr.pretty addr;
621-
let res = reachable_from_value (Analyses.ask_of_man man) (get_addr ~man ~checkBounds:false st addr None) (Addr.type_of addr) (Addr.show addr) in
626+
let res = reachable_from_value (Analyses.ask_of_man man) (get_addr ~man st addr None) (Addr.type_of addr) (Addr.show addr) in
622627
if M.tracing then M.traceu "reachability" "Reachable addresses: %a" AD.pretty res;
623628
res
624629

@@ -696,6 +701,7 @@ struct
696701

697702

698703
let reachable_top_pointers_types man (ps: AD.t) : Queries.TS.t =
704+
let@ () = GobRef.wrap AnalysisState.executing_speculative_computations true in
699705
let module TS = Queries.TS in
700706
let empty = AD.empty () in
701707
let reachable_from_address (adr: address) =
@@ -721,7 +727,7 @@ struct
721727
| Address adrs when AD.is_top adrs -> (empty,TS.bot (), true)
722728
| Address adrs -> (adrs,TS.bot (), AD.may_be_unknown adrs)
723729
| Union (t,e) -> with_field (reachable_from_value e) t
724-
| Array a -> reachable_from_value (ValueDomain.CArrays.get ~checkBounds:false (Queries.to_value_domain_ask (Analyses.ask_of_man man)) a (None, ValueDomain.ArrIdxDomain.top ()))
730+
| Array a -> reachable_from_value (ValueDomain.CArrays.get (Queries.to_value_domain_ask (Analyses.ask_of_man man)) a (None, ValueDomain.ArrIdxDomain.top ()))
725731
| Blob (e,_,_) -> reachable_from_value e
726732
| Struct s ->
727733
let join_tr (a1,t1,_) (a2,t2,_) = AD.join a1 a2, TS.join t1 t2, false in

src/cdomain/value/cdomains/arrayDomain.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ end
802802

803803
(* This is the main array out of bounds check *)
804804
let array_oob_check ( type a ) (module Idx: IntDomain.Z with type t = a) (x, l) (e, v) =
805-
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 *)
805+
if !AnalysisState.executing_speculative_computations then
806+
()
807+
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 *)
806808
let idx_before_end = Idx.lt v l in (* check whether index is before the end of the array *)
807809
let idx_after_start = Idx.ge v (Idx.of_int (Cilfacade.ptrdiff_ikind ()) Z.zero) in (* check whether the index is non-negative *)
808810
(* For an explanation of the warning types check the Pull Request #255 *)

src/cdomain/value/cdomains/valueDomain.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module type S =
1717
sig
1818
include Lattice.S
1919
type offs
20-
val eval_offset: ?checkBounds:bool -> VDQ.t -> (AD.t -> t) -> t-> offs -> exp option -> lval option -> typ -> t
20+
val eval_offset: VDQ.t -> (AD.t -> t) -> t-> offs -> exp option -> lval option -> typ -> t
2121
val update_offset: ?blob_destructive:bool -> VDQ.t -> t -> offs -> t -> exp option -> lval -> typ -> t
2222
val update_array_lengths: (exp -> t) -> t -> Cil.typ -> t
2323
val affect_move: ?replace_with_const:bool -> VDQ.t -> t -> varinfo -> (exp -> int option) -> t
@@ -901,7 +901,7 @@ struct
901901
x (* This already contains some value *)
902902

903903
(* Funny, this does not compile without the final type annotation! *)
904-
let rec eval_offset ?(checkBounds=true) (ask: VDQ.t) f (x: t) (offs:offs) (exp:exp option) (v:lval option) (t:typ): t =
904+
let rec eval_offset (ask: VDQ.t) f (x: t) (offs:offs) (exp:exp option) (v:lval option) (t:typ): t =
905905
let rec do_eval_offset (x:t) (offs:offs) (l:lval option) (o:offset option): t =
906906
if M.tracing then M.traceli "eval_offset" "do_eval_offset %a %a (%a)" pretty x Offs.pretty offs (Pretty.docOpt (CilType.Exp.pretty ())) exp;
907907
let r =
@@ -958,7 +958,7 @@ struct
958958
match x with
959959
| Array x ->
960960
let e = determine_offset ask l o exp v in
961-
do_eval_offset (CArrays.get ~checkBounds ask x (e, idx)) offs l' o'
961+
do_eval_offset (CArrays.get ask x (e, idx)) offs l' o'
962962
| Address _ ->
963963
begin
964964
do_eval_offset x offs l' o' (* this used to be `blob `address -> we ignore the index *)

0 commit comments

Comments
 (0)