From 66361961b6120267ad738a33a65846079a25c92d Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 13 Feb 2020 09:01:39 -0800 Subject: [PATCH] [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 --- infer/src/IR/Cfg.ml | 2 +- infer/src/IR/Errlog.ml | 2 +- infer/src/IR/WeakTopologicalOrder.ml | 4 +--- infer/src/al/cPredicates.ml | 2 +- infer/src/biabduction/Abs.ml | 4 ++-- infer/src/biabduction/Absarray.ml | 12 ++++++------ infer/src/biabduction/Predicates.ml | 2 +- infer/src/biabduction/Predicates.mli | 2 +- infer/src/biabduction/Prop.ml | 5 +++-- infer/src/bufferoverrun/bufferOverrunAnalysis.ml | 2 +- infer/src/checkers/SelfInBlock.ml | 8 ++++---- infer/src/clang/CType_decl.ml | 2 +- infer/src/clang/cAst_utils.ml | 4 ++-- infer/src/clang/cAst_utils.mli | 4 ++-- infer/src/clang/cEnum_decl.ml | 4 ++-- infer/src/clang/cTrans.ml | 6 +++--- 16 files changed, 32 insertions(+), 33 deletions(-) diff --git a/infer/src/IR/Cfg.ml b/infer/src/IR/Cfg.ml index a42d6e4ba..e10eaa2f1 100644 --- a/infer/src/IR/Cfg.ml +++ b/infer/src/IR/Cfg.ml @@ -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 diff --git a/infer/src/IR/Errlog.ml b/infer/src/IR/Errlog.ml index 7e974eb48..c90c2b433 100644 --- a/infer/src/IR/Errlog.ml +++ b/infer/src/IR/Errlog.ml @@ -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 diff --git a/infer/src/IR/WeakTopologicalOrder.ml b/infer/src/IR/WeakTopologicalOrder.ml index 6b08a616d..d43e7228f 100644 --- a/infer/src/IR/WeakTopologicalOrder.ml +++ b/infer/src/IR/WeakTopologicalOrder.ml @@ -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 = diff --git a/infer/src/al/cPredicates.ml b/infer/src/al/cPredicates.ml index b31949d2c..eb94ba150 100644 --- a/infer/src/al/cPredicates.ml +++ b/infer/src/al/cPredicates.ml @@ -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 ) diff --git a/infer/src/biabduction/Abs.ml b/infer/src/biabduction/Abs.ml index 415c6d208..eff1b109f 100644 --- a/infer/src/biabduction/Abs.ml +++ b/infer/src/biabduction/Abs.ml @@ -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) diff --git a/infer/src/biabduction/Absarray.ml b/infer/src/biabduction/Absarray.ml index 360f5ab63..7bd3e1958 100644 --- a/infer/src/biabduction/Absarray.ml +++ b/infer/src/biabduction/Absarray.ml @@ -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 diff --git a/infer/src/biabduction/Predicates.ml b/infer/src/biabduction/Predicates.ml index 0e572cbbd..376709c69 100644 --- a/infer/src/biabduction/Predicates.ml +++ b/infer/src/biabduction/Predicates.ml @@ -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]. *) diff --git a/infer/src/biabduction/Predicates.mli b/infer/src/biabduction/Predicates.mli index 5520036af..2c3e17561 100644 --- a/infer/src/biabduction/Predicates.mli +++ b/infer/src/biabduction/Predicates.mli @@ -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]. *) diff --git a/infer/src/biabduction/Prop.ml b/infer/src/biabduction/Prop.ml index 3254ab1c6..5c96cf3ab 100644 --- a/infer/src/biabduction/Prop.ml +++ b/infer/src/biabduction/Prop.ml @@ -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 diff --git a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml index 6e10dc3f8..ecae2f581 100644 --- a/infer/src/bufferoverrun/bufferOverrunAnalysis.ml +++ b/infer/src/bufferoverrun/bufferOverrunAnalysis.ml @@ -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 -> diff --git a/infer/src/checkers/SelfInBlock.ml b/infer/src/checkers/SelfInBlock.ml index d9270a88c..97bb8c002 100644 --- a/infer/src/checkers/SelfInBlock.ml +++ b/infer/src/checkers/SelfInBlock.ml @@ -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, _, _, _) -> diff --git a/infer/src/clang/CType_decl.ml b/infer/src/clang/CType_decl.ml index f505b1149..384aa7e5c 100644 --- a/infer/src/clang/CType_decl.ml +++ b/infer/src/clang/CType_decl.ml @@ -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 diff --git a/infer/src/clang/cAst_utils.ml b/infer/src/clang/cAst_utils.ml index f4a67027f..8e2ef7f49 100644 --- a/infer/src/clang/cAst_utils.ml +++ b/infer/src/clang/cAst_utils.ml @@ -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 diff --git a/infer/src/clang/cAst_utils.mli b/infer/src/clang/cAst_utils.mli index fb28ea3ec..98ee5f719 100644 --- a/infer/src/clang/cAst_utils.mli +++ b/infer/src/clang/cAst_utils.mli @@ -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 *) diff --git a/infer/src/clang/cEnum_decl.ml b/infer/src/clang/cEnum_decl.ml index 5b636affc..97deb1664 100644 --- a/infer/src/clang/cEnum_decl.ml +++ b/infer/src/clang/cEnum_decl.ml @@ -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 diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 74e22b2d8..110ea8c74 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -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 =