[thread-safety] fix bug in expanding callee access paths in caller

Summary:
It looks like the old code for expanding access paths assumed that `FormalMap.get_formals_indexes` assumed the returned list tuples would be sorted by index, but it's actually sorted by var name.
As a consequence, formals might be expanded into the wrong actuals.
This diff fixes the problem by not relying on `get_formals_indexes`.

Reviewed By: jberdine

Differential Revision: D6056365

fbshipit-source-id: 09f3208
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 171ee61df0
commit 0e7542a18f

@ -569,6 +569,9 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
exps ~init:accesses exps ~init:accesses
let expand_actuals actuals accesses pdesc = let expand_actuals actuals accesses pdesc =
let open Domain in
if AccessDomain.is_empty accesses then accesses
else
let rec get_access_path = function let rec get_access_path = function
| HilExp.AccessPath ap | HilExp.AccessPath ap
-> Some ap -> Some ap
@ -577,23 +580,21 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| _ | _
-> None -> None
in in
let open Domain in let formal_map = FormalMap.make pdesc in
let formals, _ = FormalMap.make pdesc |> FormalMap.get_formals_indexes |> List.unzip in
let n = min (List.length formals) (List.length actuals) in
let fmls_actls =
List.zip_exn (List.take formals n) (List.take actuals n)
|> List.filter_map ~f:(fun (fml, act) ->
match get_access_path act with Some path -> Some (fml, path) | _ -> None )
in
let fmap =
List.fold fmls_actls ~init:AccessPath.BaseMap.empty ~f:(fun acc (fml, act) ->
AccessPath.BaseMap.add fml act acc )
in
let expand_path (base, accesses as path) = let expand_path (base, accesses as path) =
try match FormalMap.get_formal_index base formal_map with
let actual = AccessPath.BaseMap.find base fmap in | Some formal_index -> (
AccessPath.append actual accesses match List.nth actuals formal_index with
with Not_found -> path | Some actual_exp -> (
match get_access_path actual_exp with
| Some actual
-> AccessPath.append actual accesses
| None
-> path )
| None
-> path )
| None
-> path
in in
let expand_pre accesses = let expand_pre accesses =
let sinks = let sinks =

Loading…
Cancel
Save