Skip to content

Commit 97edbd7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into relationalArray
1 parent f504431 commit 97edbd7

10 files changed

Lines changed: 45 additions & 52 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@
44
[submodule "g2html"]
55
path = g2html
66
url = https://github.com/goblint/g2html.git
7-
[submodule "gobview"]
8-
path = gobview
9-
url = https://github.com/goblint/gobview.git

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct
196196
let assert_type_bounds ask rel x =
197197
assert (RD.Tracked.varinfo_tracked x);
198198
match Cilfacade.get_ikind x.vtype with
199-
| ik -> (* don't add type bounds for signed when assume_none *)
199+
| ik ->
200200
let (type_min, type_max) = IntDomain.Size.range ik in
201201
(* TODO: don't go through CIL exp? *)
202202
let e1 = BinOp (Le, Lval (Cil.var x), (Cil.kintegerCilint ik type_max), intType) in
@@ -293,10 +293,10 @@ struct
293293
let castedPointer = PointerMap.to_varinfo v in
294294
Lval (Var castedPointer, offset)
295295
| BinOp (binop, e1, e2, typ) when binop = PlusPI || binop = IndexPI -> (*pointer is always on the most left*)
296-
let e2WithMult = BinOp (Mult, integer sizeOfTyp , CastE (!upointType ,e2), !upointType) in
296+
let e2WithMult = BinOp (Mult, integer sizeOfTyp , CastE (!ptrdiffType ,e2), !ptrdiffType) in
297297
BinOp (PlusA, replacePointer e1 , e2WithMult, typ)
298298
| BinOp (MinusPI, e1, e2, typ) ->
299-
let e2WithMult = BinOp (Mult, integer sizeOfTyp, CastE (!upointType ,e2), !upointType) in
299+
let e2WithMult = BinOp (Mult, integer sizeOfTyp, CastE (!ptrdiffType ,e2), !ptrdiffType) in
300300
BinOp (MinusA, replacePointer e1 , e2WithMult, typ)
301301
| e -> e
302302
in
@@ -393,9 +393,9 @@ struct
393393
if var_option != None && PointerMap.mem_varinfo (Option.get var_option) then
394394
false
395395
else
396-
let vname = RD.Var.to_string var in
396+
let vname = Apron.Var.to_string var in
397397
let locals = fundec.sformals @ fundec.slocals in
398-
match List.find_opt (fun v -> VM.var_name (Local v) = vname) locals with
398+
match List.find_opt (fun v -> VM.var_name (Local v) = vname) locals with (* TODO: optimize *)
399399
| None -> true
400400
| Some v -> any_local_reachable
401401

@@ -420,24 +420,27 @@ struct
420420
let make_callee_rel ~thread ctx f args =
421421
let fundec = Node.find_fundec ctx.node in
422422
let st = ctx.local in
423-
let argPointerMapping (x,y) = (*maps expression assigned to pointer args *)
424-
if GobConfig.get_bool "ana.apron.pointer_tracking" && isPointerType x.vtype then
423+
let argPointerMapping (x,e) = (*maps expression assigned to pointer args *)
424+
if GobConfig.get_bool "ana.apron.pointer_tracking" then
425425
begin match sizeOfTyp (Lval (Var x, NoOffset)) with
426426
| Some typSize ->
427-
(PointerMap.to_varinfo x, replacePointerWithMapping y typSize)
428-
| _ -> (x,y)
427+
let x = PointerMap.to_varinfo x in (*map pointer to helper variable*)
428+
let y = replacePointerWithMapping e typSize in (*replace right side of assignment with pointer mapping*)
429+
Some (RV.local x, y) (* assignment only works with local for some reason *)
430+
| _ -> None
429431
end
430-
else (x,y)
432+
else None
431433
in
432434
let arg_assigns =
433435
GobList.combine_short f.sformals args (* TODO: is it right to ignore missing formals/args? *)
434-
|> List.filter (fun (x, _) -> RD.Tracked.varinfo_tracked x || isPointerType x.vtype)
435-
|> List.map argPointerMapping
436-
|> List.map (Tuple2.map1 (fun x ->
437-
if PointerMap.mem_varinfo x then
438-
RV.local x (* assignment only works with local for some reason *)
436+
|> List.filter_map (fun (x, e) ->
437+
if RD.Tracked.varinfo_tracked x then
438+
Some (RV.arg x, e)
439+
else if isPointerType x.vtype then
440+
argPointerMapping (x,e)
439441
else
440-
RV.arg x))
442+
None
443+
)
441444
in
442445
let reachableAllocSizeVars = (* get a list of all possible addresses arg may point to *)
443446
GobList.combine_short f.sformals args |> List.filter (fun (x, _) -> isPointerType x.vtype) |> List.map ((fun (_,x) -> mayPointToList ctx x)) |> List.flatten
@@ -461,10 +464,9 @@ struct
461464
let any_local_reachable = any_local_reachable fundec reachable_from_args in
462465
RD.remove_filter_with new_rel (fun var ->
463466
match RV.find_metadata var with
464-
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) && not (List.mem_cmp RD.Var.compare var arg_vars) -> if M.tracing then M.trace "re" "remove Local: %a\n" (docOpt (CilType.Varinfo.pretty())) (RV.to_cil_varinfo var);true (* remove caller locals provided they are unreachable *)
465-
| Some (Arg _) when not (List.mem_cmp RD.Var.compare var arg_vars) -> if M.tracing then M.trace "re" "remove Arg: %a\n" (docOpt (CilType.Varinfo.pretty())) (RV.to_cil_varinfo var);true (* remove caller args, but keep just added args *)
466-
| _ ->
467-
match RV.to_cil_varinfo var with
467+
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) && not (List.mem_cmp Apron.Var.compare var arg_vars) -> true (* remove caller locals provided they are unreachable *)
468+
| Some (Arg _) when not (List.mem_cmp Apron.Var.compare var arg_vars) -> true (* remove caller args, but keep just added args *)
469+
| _ -> match RV.to_cil_varinfo var with
468470
| None -> false
469471
| Some var -> filterAllocVar var reachableAllocSizeVars (* check if the allocMapping var is reachable from the new function *)
470472
(* keep everything else (just added args, globals, global privs) *)
@@ -889,15 +891,15 @@ struct
889891
if M.tracing then M.trace "OOB" "st: %a\n" RD.pretty st.rel;
890892
begin match sizeOfTyp e1 with
891893
| Some typSize ->
892-
let e2Mult = BinOp (Mult, e2, integer typSize, TInt ( Cilfacade.ptrdiff_ikind (), []) )in
894+
let e2Mult = BinOp (Mult, e2, integer typSize, TInt (IInt, []) )in
893895
let isAfterZero =
894896
begin match IntDomain.IntDomTuple.minimal i with
895897
| None -> VDQ.ID.top ()
896898
| Some min ->
897899
begin
898900
try
899901
let min = Z.to_int min in
900-
let aZExp = BinOp (binop, integer min, e2Mult, TInt (Cilfacade.ptrdiff_ikind (),[])) in
902+
let aZExp = BinOp (binop, integer min, e2Mult, TInt (IInt, [])) in
901903
let afterZero = Cilfacade.makeBinOp Le Cil.zero aZExp in
902904
eval_int afterZero (no_overflow ask afterZero)
903905
with
@@ -911,7 +913,7 @@ struct
911913
| Some i ->
912914
begin try
913915
let i = Z.to_int i + structOffset in
914-
let relExp = BinOp (binop, integer i, e2Mult, TInt (Cilfacade.ptrdiff_ikind () ,[])) in
916+
let relExp = BinOp (binop, integer i, e2Mult, TInt (IInt, [])) in
915917
inBoundsForAllAddresses relExp
916918
with
917919
| Z.Overflow -> VDQ.ID.top ()

src/analyses/base.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ struct
12891289
(match r with
12901290
| Array a ->
12911291
(* unroll into array for Calloc calls *)
1292-
(match ValueDomain.CArrays.get (Queries.to_value_domain_ask (Analyses.ask_of_ctx ctx)) a (None, (IdxDom.of_int (Cilfacade.ptrdiff_ikind ()) BI.zero)) with
1292+
(match ValueDomain.CArrays.get (Queries.to_value_domain_ask (Analyses.ask_of_ctx ctx)) a (None, (IdxDom.of_int (Cilfacade.ptrdiff_ikind ()) BI.zero)) None with
12931293
| Blob (_,s,_) -> `Lifted s
12941294
| _ -> Queries.Result.top q
12951295
)

src/analyses/memOutOfBounds.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ struct
6969
in
7070
host_contains_a_ptr host || offset_contains_a_ptr offset
7171

72-
let points_to_heap_only ctx ptr =
72+
let points_to_alloc_only ctx ptr =
7373
match ctx.ask (Queries.MayPointTo ptr) with
7474
| a when not (Queries.AD.is_top a)->
7575
Queries.AD.for_all (function
76-
| Addr (v, o) -> ctx.ask (Queries.IsHeapVar v)
76+
| Addr (v, o) -> ctx.ask (Queries.IsAllocVar v)
7777
| _ -> false
7878
) a
7979
| _ -> false
8080

8181
let get_size_of_ptr_target ctx ptr =
82-
if points_to_heap_only ctx ptr then
82+
if points_to_alloc_only ctx ptr then
8383
(* Ask for BlobSize from the base address (the second component being set to true) in order to avoid BlobSize giving us bot *)
8484
ctx.ask (Queries.BlobSize {exp = ptr; base_address = true})
8585
else

src/cdomain/value/cdomains/arrayDomain.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ sig
4545
type idx
4646
type value
4747

48-
val domain_of_t: t -> domain
49-
50-
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> (lval option * int) option -> value
5148
val set: VDQ.t -> t -> Basetype.CilExp.t option * idx -> value -> t
5249
val make: ?varAttr:attributes -> ?typAttr:attributes -> idx -> value -> t
5350
val length: t -> idx option
@@ -70,7 +67,7 @@ sig
7067
include S0
7168

7269
val domain_of_t: t -> domain
73-
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> value
70+
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> (lval option * int) option -> value
7471
end
7572

7673
module type Str =
@@ -209,7 +206,7 @@ struct
209206
let extract x default = match x with
210207
| Some c -> c
211208
| None -> default
212-
let get ?(checkBounds=true) (ask: VDQ.t) (xl, xr) (_,i) arr =
209+
let get ?(checkBounds=true) (ask: VDQ.t) (xl, xr) (_,i) _ =
213210
let search_unrolled_values min_i max_i =
214211
let rec subjoin l i = match l with
215212
| [] -> Val.bot ()
@@ -403,7 +400,7 @@ struct
403400
("m", Val.to_yojson xm);
404401
("r", Val.to_yojson xr) ]
405402

406-
let get ?(checkBounds=true) (ask:VDQ.t) (x:t) (i,_) _ =
403+
let get ?(checkBounds=true) (ask:VDQ.t) (x:t) (i,_) _=
407404
match x, i with
408405
| Joint v, _ -> v
409406
| Partitioned (e, (xl, xm, xr)), Some i' ->
@@ -1127,7 +1124,7 @@ struct
11271124
in
11281125

11291126
(* warn if index is (potentially) out of bounds *)
1130-
array_oob_check (module Idx) (Nulls.get_set Possibly, size) (e, i);
1127+
array_oob_check (module Idx) (Nulls.get_set Possibly, size) (e, i) None ask;
11311128
let nulls = match max_i with
11321129
(* if no maximum number in index interval *)
11331130
| None ->
@@ -1822,8 +1819,8 @@ struct
18221819

18231820
let domain_of_t (t_f, _) = A.domain_of_t t_f
18241821

1825-
let get ?(checkBounds=true) (ask: VDQ.t) (t_f, t_n) i =
1826-
let f_get = A.get ~checkBounds ask t_f i in
1822+
let get ?(checkBounds=true) (ask: VDQ.t) (t_f, t_n) i arrExpDim=
1823+
let f_get = A.get ~checkBounds ask t_f i arrExpDim in
18271824
if get_bool "ana.base.arrays.nullbytes" then
18281825
let n_get = N.get ask t_n i in
18291826
match Val.get_ikind f_get, n_get with

src/cdomain/value/cdomains/arrayDomain.mli

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ sig
2121
type value
2222
(** The abstract domain of values stored in the array. *)
2323

24-
val domain_of_t: t -> domain
25-
(* Returns the domain used for the array*)
26-
27-
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> (lval option * int) option -> value
28-
(** Returns the element residing at the given index. *)
29-
3024
val set: VDQ.t -> t -> Basetype.CilExp.t option * idx -> value -> t
3125
(** Returns a new abstract value, where the given index is replaced with the
3226
* given element. *)
@@ -68,7 +62,7 @@ sig
6862
val domain_of_t: t -> domain
6963
(* Returns the domain used for the array*)
7064

71-
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> value
65+
val get: ?checkBounds:bool -> VDQ.t -> t -> Basetype.CilExp.t option * idx -> (lval option * int) option -> value
7266
(** Returns the element residing at the given index. *)
7367
end
7468

src/cdomain/value/cdomains/valueDomain.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ struct
930930
in
931931
do_eval_offset ask f x offs exp l o v t 0
932932

933-
let update_offset (ask: VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval) (t:typ): t =
933+
let update_offset ?(blob_destructive=false) (ask: VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (v:lval) (t:typ): t =
934934
let rec do_update_offset (ask:VDQ.t) (x:t) (offs:offs) (value:t) (exp:exp option) (l:lval option) (o:offset option) (v:lval) (t:typ) (depth:int):t =
935935
if M.tracing then M.traceli "update_offset" "do_update_offset %a %a (%a) %a\n" pretty x Offs.pretty offs (Pretty.docOpt (CilType.Exp.pretty ())) exp pretty value;
936936
let mu = function Blob (Blob (y, s', orig), s, orig2) -> Blob (y, ID.join s s',orig) | x -> x in

src/domains/queries.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,14 @@ struct
332332
| Any (EvalMutexAttr _ ) -> 50
333333
| Any ThreadCreateIndexedNode -> 51
334334
| Any ThreadsJoinedCleanly -> 52
335-
| Any (TmpSpecial _) -> 53
336-
| Any (IsAllocVar _) -> 54
337-
| Any (MayBeOutOfBounds _) -> 55
338-
| Any (MayOverflow _) -> 56
339-
| Any (AllocMayBeOutOfBounds _) -> 56
335+
| Any (MustTermLoop _) -> 53
336+
| Any MustTermAllLoops -> 54
337+
| Any IsEverMultiThreaded -> 55
338+
| Any (TmpSpecial _) -> 56
339+
| Any (IsAllocVar _) -> 57
340+
| Any (MayBeOutOfBounds _) -> 58
341+
| Any (MayOverflow _) -> 59
342+
| Any (AllocMayBeOutOfBounds _) -> 60
340343

341344
let rec compare a b =
342345
let r = Stdlib.compare (order a) (order b) in
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)