@@ -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 ()
0 commit comments