diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 66f47ea8e..cc577d7ec 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -467,6 +467,8 @@ let rec is_array_of_cpp_class typ = match typ.desc with Tarray (typ, _, _) -> is_array_of_cpp_class typ | _ -> is_cpp_class typ +let is_pointer typ = match typ.desc with Tptr _ -> true | _ -> false + let is_pointer_to_cpp_class typ = match typ.desc with Tptr (t, _) -> is_cpp_class t | _ -> false let has_block_prefix s = diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 19010a8d1..db987232f 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -250,6 +250,8 @@ val is_array_of_cpp_class : t -> bool val is_pointer_to_cpp_class : t -> bool +val is_pointer : t -> bool + val has_block_prefix : string -> bool val is_block_type : t -> bool diff --git a/infer/src/backend/dotty.ml b/infer/src/backend/dotty.ml index 07b5e74b4..0dc91a5b0 100644 --- a/infer/src/backend/dotty.ml +++ b/infer/src/backend/dotty.ml @@ -1160,12 +1160,11 @@ let pp_cfgnodename pname fmt (n: Procdesc.Node.t) = let pp_etlist byvals fmt etl = List.iteri - ~f:(fun index (id, ({Typ.desc} as ty)) -> - let is_ptr = match desc with Tptr _ -> true | _ -> false in + ~f:(fun index (id, typ) -> let byval_mark = - if is_ptr && List.mem byvals index ~equal:Int.equal then "(byval)" else "" + if Typ.is_pointer typ && List.mem byvals index ~equal:Int.equal then "(byval)" else "" in - Format.fprintf fmt " %a:%a%s" Mangled.pp id (Typ.pp_full Pp.text) ty byval_mark ) + Format.fprintf fmt " %a:%a%s" Mangled.pp id (Typ.pp_full Pp.text) typ byval_mark ) etl diff --git a/infer/src/checkers/uninit.ml b/infer/src/checkers/uninit.ml index 41dc74cf0..db3c99b0d 100644 --- a/infer/src/checkers/uninit.ml +++ b/infer/src/checkers/uninit.ml @@ -31,8 +31,6 @@ end) let blacklisted_functions = [BuiltinDecl.__set_array_length] -let is_type_pointer t = match t.Typ.desc with Typ.Tptr _ -> true | _ -> false - let rec is_basic_type t = match t.Typ.desc with | Tint _ | Tfloat _ | Tvoid -> @@ -87,11 +85,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let function_expects_a_pointer_as_nth_param callee_pname idx = - match nth_formal_param callee_pname idx with - | Some (_, typ) -> - is_type_pointer typ - | _ -> - false + match nth_formal_param callee_pname idx with Some (_, typ) -> Typ.is_pointer typ | _ -> false let is_struct_field_passed_by_ref call t al idx = @@ -103,7 +97,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct ~f:(fun idx e -> match e with | HilExp.AccessPath ((var, t), al) - when should_report_var pdesc tenv uninit_vars ((var, t), al) && not (is_type_pointer t) + when should_report_var pdesc tenv uninit_vars ((var, t), al) && not (Typ.is_pointer t) && not (is_struct_field_passed_by_ref call t al idx) -> report_intra ((var, t), al) loc (snd extras) | _ -> @@ -171,7 +165,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct HilExp.is_null_literal rhs (* the rhs has type int when assigning the lhs to null *) || Option.equal Typ.equal (AccessPath.get_typ lhs tenv) (HilExp.get_typ tenv rhs) - && is_type_pointer (snd (fst lhs)) + && Typ.is_pointer (snd (fst lhs)) (* checks that the set of initialized formal parameters defined in the precondition of @@ -206,7 +200,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let exec_instr (astate: Domain.astate) {ProcData.pdesc; ProcData.extras; ProcData.tenv} _ (instr: HilInstr.t) = let update_prepost (((_, lhs_typ), apl) as lhs_ap) rhs = - if FormalMap.is_formal (fst lhs_ap) (fst extras) && is_type_pointer lhs_typ + if FormalMap.is_formal (fst lhs_ap) (fst extras) && Typ.is_pointer lhs_typ && (not (is_pointer_assignment tenv lhs_ap rhs) || List.length apl > 0) then let pre' = D.add lhs_ap (fst astate.prepost) in @@ -225,7 +219,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct in let prepost = update_prepost lhs_ap rhs in (* check on lhs_typ to avoid false positive when assigning a pointer to another *) - if should_report_var pdesc tenv uninit_vars (rhs_base, al) && not (is_type_pointer lhs_typ) + if should_report_var pdesc tenv uninit_vars (rhs_base, al) && not (Typ.is_pointer lhs_typ) then report_intra (rhs_base, al) loc (snd extras) ; {astate with uninit_vars; prepost} | Assign (((lhs_ap, apl) as lhs), rhs, _) -> diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 5bc376328..b808cf9e4 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -500,7 +500,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s extract_exp_from_list pre_trans_result.exps "WARNING: in Field dereference we expect to know the object@\n" in - let is_pointer_typ = match class_typ.desc with Typ.Tptr _ -> true | _ -> false in + let is_pointer_typ = Typ.is_pointer class_typ in let class_typ = match class_typ.desc with Typ.Tptr (t, _) -> t | _ -> class_typ in L.(debug Capture Verbose) "Type is '%s' @." (Typ.to_string class_typ) ; let class_tname =