Skip to content

Commit 0dd89ad

Browse files
relationAnalysis: Drastically simplify pass_to_callee
1 parent 0604e65 commit 0dd89ad

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,14 @@ struct
291291
in
292292
List.fold (fun vs e -> VS.join vs (to_vs e)) (VS.empty ()) args
293293

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

305303
let make_callee_rel ~thread man f args =
306304
let fundec = Node.find_fundec man.node in
@@ -328,7 +326,7 @@ struct
328326
let any_local_reachable = any_local_reachable fundec reachable_from_args in
329327
RD.remove_filter_with new_rel (fun var ->
330328
match RV.find_metadata var with
331-
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) -> true (* remove caller locals provided they are unreachable *)
329+
| Some (Local _) when not (belongs_to_fundec fundec var || any_local_reachable) -> true (* remove caller locals provided they are unreachable *)
332330
| Some (Arg _) when not (List.mem_cmp Apron.Var.compare var arg_vars) -> true (* remove caller args, but keep just added args *)
333331
| _ -> false (* keep everything else (just added args, globals, global privs) *)
334332
);
@@ -425,7 +423,7 @@ struct
425423
let tainted_vars = TaintPartialContexts.conv_varset tainted in
426424
let new_rel = RD.keep_filter st.rel (fun var ->
427425
match RV.find_metadata var with
428-
| Some (Local _) when not (pass_to_callee fundec any_local_reachable var) -> true (* keep caller locals, provided they were not passed to the function *)
426+
| Some (Local _) when not (belongs_to_fundec fundec var || any_local_reachable) -> true (* keep caller locals, provided they were not passed to the function *)
429427
| Some (Arg _) -> true (* keep caller args *)
430428
| 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 *)
431429
| 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 *)

0 commit comments

Comments
 (0)