diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 1a8fa5322..c29609dbf 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -111,7 +111,7 @@ module Node = struct (** Get the source location of the last instruction in the node *) let get_last_loc n = - match List.rev (get_instrs n) with instr :: _ -> Sil.instr_get_loc instr | [] -> n.loc + n |> get_instrs |> List.last |> Option.value_map ~f:Sil.instr_get_loc ~default:n.loc let pp_id f id = F.pp_print_int f id diff --git a/infer/src/backend/preanal.ml b/infer/src/backend/preanal.ml index cde22f8aa..f986dc0db 100644 --- a/infer/src/backend/preanal.ml +++ b/infer/src/backend/preanal.ml @@ -74,7 +74,7 @@ module NullifyTransferFunctions = struct let last_instr_in_node node = let get_last_instr () = let instrs = CFG.instrs node in - match List.rev instrs with instr :: _ -> instr | [] -> Sil.skip_instr + List.last instrs |> Option.value ~default:Sil.skip_instr in if phys_equal node !cache_node then !cache_instr else @@ -135,9 +135,10 @@ let add_nullify_instrs pdesc tenv liveness_inv_map = let node_add_nullify_instructions node pvars = let loc = Procdesc.Node.get_last_loc node in let nullify_instrs = - List.filter ~f:is_local pvars |> List.map ~f:(fun pvar -> Sil.Nullify (pvar, loc)) + List.rev_filter_map pvars ~f:(fun pvar -> + if is_local pvar then Some (Sil.Nullify (pvar, loc)) else None ) in - if nullify_instrs <> [] then Procdesc.Node.append_instrs node (List.rev nullify_instrs) + if nullify_instrs <> [] then Procdesc.Node.append_instrs node nullify_instrs in let node_add_removetmps_instructions node ids = if ids <> [] then