Skip to content

Commit

Permalink
relationAnalysis: Drastically simplify pass_to_callee
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Feb 18, 2025
1 parent 0604e65 commit 0dd89ad
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/analyses/apron/relationAnalysis.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,14 @@ struct
in
List.fold (fun vs e -> VS.join vs (to_vs e)) (VS.empty ()) args

let pass_to_callee fundec any_local_reachable var =
(* TODO: currently, we pass all locals of the caller to the callee, provided one of them is reachbale to preserve relationality *)
let belongs_to_fundec fundec var =
(* TODO: currently, we pass all locals of the caller to the callee, provided one of them is reachable to preserve relationality *)
(* there should be smarter ways to do this, e.g. by keeping track of which values are written etc. ... *)
(* See, e.g, Beckschulze E, Kowalewski S, Brauer J (2012) Access-based localization for octagons. Electron Notes Theor Comput Sci 287:29–40 *)
(* Also, a local *)
let vname = GobApron.Var.show var in
let locals = fundec.sformals @ fundec.slocals in
match List.find_opt (fun v -> VM.var_name (Local v) = vname) locals with (* TODO: optimize *)
| None -> true
| Some v -> any_local_reachable
let equiv v = VM.var_name (Local v) = vname in
(not @@ List.exists equiv fundec.sformals) && (not @@ List.exists equiv fundec.slocals)

let make_callee_rel ~thread man f args =
let fundec = Node.find_fundec man.node in
Expand Down Expand Up @@ -328,7 +326,7 @@ struct
let any_local_reachable = any_local_reachable fundec reachable_from_args in
RD.remove_filter_with new_rel (fun var ->
match RV.find_metadata var with
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) -> true (* remove caller locals provided they are unreachable *)
| Some (Local _) when not (belongs_to_fundec fundec var || any_local_reachable) -> true (* remove caller locals provided they are unreachable *)
| Some (Arg _) when not (List.mem_cmp Apron.Var.compare var arg_vars) -> true (* remove caller args, but keep just added args *)
| _ -> false (* keep everything else (just added args, globals, global privs) *)
);
Expand Down Expand Up @@ -425,7 +423,7 @@ struct
let tainted_vars = TaintPartialContexts.conv_varset tainted in
let new_rel = RD.keep_filter st.rel (fun var ->
match RV.find_metadata var with
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) -> true (* keep caller locals, provided they were not passed to the function *)
| Some (Local _) when not (belongs_to_fundec fundec var || any_local_reachable) -> true (* keep caller locals, provided they were not passed to the function *)
| Some (Arg _) -> true (* keep caller args *)
| Some ((Local _ | Global _)) when not (RD.mem_var new_fun_rel var) -> false (* remove locals and globals, for which no record exists in the new_fun_apr *)
| Some ((Local v | Global v)) when not (TaintPartialContexts.VS.mem v tainted_vars) -> true (* keep locals and globals, which have not been touched by the call *)
Expand Down

0 comments on commit 0dd89ad

Please sign in to comment.