[ocaml] more Not_found_s

Summary:
Core v13 APIs stopped raising `Not_found` and instead raise
`Not_found_s`, which wreaks havoc in our codebase. Carefully inspect
each `Not_found` and add `Not_found_s` where needed (that way it's
compatible with both Core v12 and v13 for now).

Reviewed By: jberdine

Differential Revision: D19861585

fbshipit-source-id: 9a5361ae9
master
Jules Villard 5 years ago committed by Facebook Github Bot
parent a684a1edf0
commit 66361961b6

@ -131,7 +131,7 @@ let proc_inline_synthetic_methods cfg pdesc : unit =
if is_access || is_bridge || is_synthetic then
inline_synthetic_method ret_id_typ etl pd loc |> Option.value ~default:instr
else instr
| exception Caml.Not_found ->
| exception (Caml.Not_found | Not_found_s _) ->
instr )
| _ ->
instr

@ -223,7 +223,7 @@ let add_issue tbl err_key (err_datas : ErrDataSet.t) : bool =
else (
ErrLogHash.replace tbl err_key (ErrDataSet.union err_datas current_eds) ;
true )
with Caml.Not_found ->
with Caml.Not_found | Not_found_s _ ->
ErrLogHash.add tbl err_key err_datas ;
true

@ -173,9 +173,7 @@ module Bourdoncle_SCC (CFG : PreProcCfg) = struct
current strictly connected component.
*)
record_head node_dfn
| exception Caml.Not_found ->
push_on_stack node
| exception Not_found_s _ ->
| exception (Not_found_s _ | Caml.Not_found) ->
push_on_stack node
in
let rec process_stack partition =

@ -703,7 +703,7 @@ let is_property_pointer_type an =
CAst_utils.name_of_typedef_type_info tti |> QualifiedCppName.to_qual_string
in
String.equal typedef_str CFrontend_config.id_cl
| exception Caml.Not_found ->
| exception (Not_found_s _ | Caml.Not_found) ->
false
| _ ->
false )

@ -63,7 +63,7 @@ let create_condition_ls ids_private id_base p_leftover (inst : Predicates.subst)
let insts_of_public_ids = Predicates.sub_range inst_public in
let inst_of_base =
try Predicates.sub_find (Ident.equal id_base) inst_public
with Caml.Not_found -> assert false
with Not_found_s _ | Caml.Not_found -> assert false
in
let insts_of_private_ids = Predicates.sub_range inst_private in
(insts_of_private_ids, insts_of_public_ids, inst_of_base)
@ -216,7 +216,7 @@ let mk_rule_lsls_ls tenv k1 k2 impl_ok1 impl_ok2 para =
let find x = sub_find (equal x) inst in
try
(find id_base, find id_next, find id_end)
with Not_found -> assert false in
with Not_found_s _ | Caml.Not_found -> assert false in
let spooky_case _ =
(equal_lseg_kind Lseg_PE k_res)
&& (check_allocatedness p_leftover inst_end)

@ -49,7 +49,7 @@ module StrexpMatch : sig
type t
val find_path : sigma -> path -> t
(** Find a strexp at the given path. Can raise [Not_found] *)
(** Find a strexp at the given path. Can raise [Not_found_s/Caml.Not_found] *)
val find : Tenv.t -> sigma -> (strexp_data -> bool) -> t list
(** Find a strexp with the given property. *)
@ -165,14 +165,14 @@ end = struct
(** Store hpred using physical equality, and offset list for an array *)
type t = sigma * Predicates.hpred * syn_offset list
(** Find an array at the given path. Can raise [Not_found] *)
(** Find an array at the given path. Can raise [Not_found_s/Caml.Not_found] *)
let find_path sigma (root, syn_offs) : t =
let filter = function Predicates.Hpointsto (e, _, _) -> Exp.equal root e | _ -> false in
let hpred = List.find_exn ~f:filter sigma in
(sigma, hpred, syn_offs)
(** Find a sub strexp with the given property. Can raise [Not_found] *)
(** Find a sub strexp with the given property. Can raise [Not_found_s/Caml.Not_found] *)
let find tenv (sigma : sigma) (pred : strexp_data -> bool) : t list =
let found = ref [] in
let rec find_offset_sexp sigma_other hpred root offs se (typ : Typ.t) =
@ -431,7 +431,7 @@ let blur_array_index tenv (p : Prop.normal Prop.t) (path : StrexpMatch.path) (in
let sigma_fp' = StrexpMatch.replace_index tenv true matched_fp index fresh_index in
Prop.set p ~sigma_fp:sigma_fp'
else Prop.expose p
with Caml.Not_found -> Prop.expose p
with Not_found_s _ | Caml.Not_found -> Prop.expose p
in
let p3 =
let matched = StrexpMatch.find_path p.Prop.sigma path in
@ -445,7 +445,7 @@ let blur_array_index tenv (p : Prop.normal Prop.t) (path : StrexpMatch.path) (in
prop_replace_path_index tenv p3 path map
in
Prop.normalize tenv p4
with Caml.Not_found -> p
with Not_found_s _ | Caml.Not_found -> p
(** Given [p] containing an array at [root], blur [indices] in it *)
@ -474,7 +474,7 @@ let keep_only_indices tenv (p : Prop.normal Prop.t) (path : StrexpMatch.path) (i
(sigma', true)
| _ ->
(sigma, false)
with Caml.Not_found -> (sigma, false)
with Not_found_s _ | Caml.Not_found -> (sigma, false)
in
prop_update_sigma_and_fp_sigma tenv p prune_sigma

@ -866,7 +866,7 @@ let sub_symmetric_difference sub1_in sub2_in =
(** [sub_find filter sub] returns the expression associated to the first identifier that satisfies
[filter]. Raise [Not_found] if there isn't one. *)
[filter]. Raise [Not_found_s/Caml.Not_found] if there isn't one. *)
let sub_find filter (sub : subst) = snd (List.find_exn ~f:(fun (i, _) -> filter i) sub)
(** [sub_filter filter sub] restricts the domain of [sub] to the identifiers satisfying [filter]. *)

@ -301,7 +301,7 @@ val sub_symmetric_difference : subst -> subst -> subst * subst * subst
val sub_find : (Ident.t -> bool) -> subst -> Exp.t
(** [sub_find filter sub] returns the expression associated to the first identifier that satisfies
[filter]. Raise [Not_found] if there isn't one. *)
[filter]. Raise [Not_found_s/Caml.Not_found] if there isn't one. *)
val sub_filter : (Ident.t -> bool) -> subst -> subst
(** [sub_filter filter sub] restricts the domain of [sub] to the identifiers satisfying [filter]. *)

@ -2099,9 +2099,10 @@ let rec idlist_assoc id = function
if Ident.equal i id then x else idlist_assoc id l
let ident_captured_ren ren id = try idlist_assoc id ren with Caml.Not_found -> id
let ident_captured_ren ren id =
(* If not defined in ren, id should be mapped to itself *)
try idlist_assoc id ren with Caml.Not_found -> id
(* If not defined in ren, id should be mapped to itself *)
let rec exp_captured_ren ren (e : Exp.t) : Exp.t =
match e with

@ -115,7 +115,7 @@ module TransferFunctions = struct
Some loc
| _ ->
None
with Caml.Not_found -> None )
with Not_found_s _ | Caml.Not_found -> None )
in
match Dom.Mem.find_ret_alias callee_exit_mem with
| Bottom ->

@ -182,7 +182,7 @@ module TransferFunctions = struct
in
{Domain.vars; strongVars}
else astate
with Not_found_s _ | Caml.Not_found -> astate
with Caml.Not_found -> astate
let make_trace_unchecked_strongself (domain : Domain.t) =
@ -225,7 +225,7 @@ module TransferFunctions = struct
in
let ltr = make_trace_unchecked_strongself domain in
Reporting.log_error summary ~ltr ~loc IssueType.strong_self_not_checked message
with Not_found_s _ | Caml.Not_found -> ()
with Caml.Not_found -> ()
let report_unchecked_strongself_issues_on_exps (domain : Domain.t) summary (instr : Sil.instr) =
@ -336,7 +336,7 @@ module TransferFunctions = struct
if not isChecked.checked then
Vars.add id {pvar; typ; loc; kind= UNCHECKED_STRONG_SELF} astate.vars
else astate.vars
with Not_found_s _ | Caml.Not_found -> astate.vars
with Caml.Not_found -> astate.vars
in
{astate with vars}
| Store {e1= Lvar pvar; e2= Var id; typ= pvar_typ; loc} ->
@ -346,7 +346,7 @@ module TransferFunctions = struct
if is_captured_weak_self attributes binding_for_id && Typ.is_strong_pointer pvar_typ
then StrongEqualToWeakCapturedVars.add pvar {checked= false; loc} astate.strongVars
else astate.strongVars
with Not_found_s _ | Caml.Not_found -> astate.strongVars
with Caml.Not_found -> astate.strongVars
in
{astate with strongVars}
| Prune (Var id, _, _, _) ->

@ -359,7 +359,7 @@ let get_translate_as_friend_decl decl_list =
Some t_ptr
| _ ->
None
| exception Caml.Not_found ->
| exception (Not_found_s _ | Caml.Not_found) ->
None

@ -143,7 +143,7 @@ let update_sil_types_map type_ptr sil_type =
Clang_ast_extend.TypePointerMap.add type_ptr sil_type !CFrontend_config.sil_types_map
let update_enum_map enum_constant_pointer sil_exp =
let update_enum_map_exn enum_constant_pointer sil_exp =
let predecessor_pointer_opt, _ =
ClangPointers.Map.find_exn !CFrontend_config.enum_map enum_constant_pointer
in
@ -158,7 +158,7 @@ let add_enum_constant enum_constant_pointer predecessor_pointer_opt =
ClangPointers.Map.set !CFrontend_config.enum_map ~key:enum_constant_pointer ~data:enum_map_value
let get_enum_constant_exp enum_constant_pointer =
let get_enum_constant_exp_exn enum_constant_pointer =
ClangPointers.Map.find_exn !CFrontend_config.enum_map enum_constant_pointer

@ -33,11 +33,11 @@ val get_property_of_ivar : Clang_ast_t.pointer -> Clang_ast_t.decl option
val update_sil_types_map : Clang_ast_t.type_ptr -> Typ.desc -> unit
val update_enum_map : Clang_ast_t.pointer -> Exp.t -> unit
val update_enum_map_exn : Clang_ast_t.pointer -> Exp.t -> unit
val add_enum_constant : Clang_ast_t.pointer -> Clang_ast_t.pointer option -> unit
val get_enum_constant_exp : Clang_ast_t.pointer -> Clang_ast_t.pointer option * Exp.t option
val get_enum_constant_exp_exn : Clang_ast_t.pointer -> Clang_ast_t.pointer option * Exp.t option
val get_qualified_name : ?linters_mode:bool -> Clang_ast_t.named_decl_info -> QualifiedCppName.t
(** returns sanitized, fully qualified name given name info *)

@ -16,9 +16,9 @@ open! IStd
(* to the map. *)
let add_enum_constant_to_map_if_needed decl_pointer pred_decl_opt =
try
ignore (CAst_utils.get_enum_constant_exp decl_pointer) ;
ignore (CAst_utils.get_enum_constant_exp_exn decl_pointer) ;
true
with Caml.Not_found ->
with Not_found_s _ | Caml.Not_found ->
CAst_utils.add_enum_constant decl_pointer pred_decl_opt ;
false

@ -865,16 +865,16 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let zero = Exp.Const (Const.Cint IntLit.zero) in
try
let prev_enum_constant_opt, sil_exp_opt =
CAst_utils.get_enum_constant_exp enum_constant_pointer
CAst_utils.get_enum_constant_exp_exn enum_constant_pointer
in
match sil_exp_opt with
| Some exp ->
exp
| None ->
let exp = enum_const_eval context enum_constant_pointer prev_enum_constant_opt zero in
CAst_utils.update_enum_map enum_constant_pointer exp ;
CAst_utils.update_enum_map_exn enum_constant_pointer exp ;
exp
with Caml.Not_found -> zero
with Not_found_s _ | Caml.Not_found -> zero
and enum_constant_trans trans_state decl_ref =

Loading…
Cancel
Save