diff --git a/infer/src/IR/Attributes.ml b/infer/src/IR/Attributes.ml index 29f49b499..5a7ed5e55 100644 --- a/infer/src/IR/Attributes.ml +++ b/infer/src/IR/Attributes.ml @@ -135,7 +135,7 @@ let load_defined pname = Typ.Procname.SQLite.serialize pname |> find ~defined:tr let find_file_capturing_procedure pname = Option.map (load pname) ~f:(fun proc_attributes -> - let source_file = proc_attributes.ProcAttributes.source_file_captured in + let source_file = proc_attributes.ProcAttributes.translation_unit in let origin = (* Procedure coming from include files if it has different location than the file where it was captured. *) diff --git a/infer/src/IR/Cfg.ml b/infer/src/IR/Cfg.ml index decafd3e8..6792c6bf8 100644 --- a/infer/src/IR/Cfg.ml +++ b/infer/src/IR/Cfg.ml @@ -73,7 +73,7 @@ let save_attributes source_file cfg = let loc = attributes.loc in let attributes' = let loc' = if Location.equal loc Location.dummy then {loc with file= source_file} else loc in - {attributes with loc= loc'; source_file_captured= source_file} + {attributes with loc= loc'; translation_unit= source_file} in Attributes.store attributes' in diff --git a/infer/src/IR/ProcAttributes.ml b/infer/src/IR/ProcAttributes.ml index a5a0de7eb..771855885 100644 --- a/infer/src/IR/ProcAttributes.ml +++ b/infer/src/IR/ProcAttributes.ml @@ -103,14 +103,13 @@ type t = ; is_synthetic_method: bool (** the procedure is a synthetic method *) ; clang_method_kind: clang_method_kind (** the kind of method the procedure is *) ; loc: Location.t (** location of this procedure in the source code *) - ; translation_unit: SourceFile.t option (** translation unit to which the procedure belongs *) + ; translation_unit: SourceFile.t (** translation unit to which the procedure belongs *) ; mutable locals: var_data list (** name, type and attributes of local variables *) ; method_annotation: Annot.Method.t (** annotations for all methods *) ; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *) ; proc_flags: proc_flags (** flags of the procedure *) ; proc_name: Typ.Procname.t (** name of the procedure *) - ; ret_type: Typ.t (** return type *) - ; source_file_captured: SourceFile.t (** source file where the procedure was captured *) } + ; ret_type: Typ.t (** return type *) } [@@deriving compare] let default proc_name = @@ -133,14 +132,13 @@ let default proc_name = ; is_synthetic_method= false ; clang_method_kind= C_FUNCTION ; loc= Location.dummy - ; translation_unit= None + ; translation_unit= SourceFile.invalid __FILE__ ; locals= [] ; method_annotation= Annot.Method.empty ; objc_accessor= None ; proc_flags= proc_flags_empty () ; proc_name - ; ret_type= Typ.mk Typ.Tvoid - ; source_file_captured= SourceFile.invalid __FILE__ } + ; ret_type= Typ.mk Typ.Tvoid } let pp_parameters = @@ -173,14 +171,11 @@ let pp f ; objc_accessor ; proc_flags ; proc_name - ; ret_type - ; source_file_captured }[@warning "+9"]) = + ; ret_type }[@warning "+9"]) = let default = default proc_name in let pp_bool_default ~default title b f () = if not (Bool.equal default b) then F.fprintf f "; %s= %b@," title b in - F.fprintf f "@[{ proc_name= %a@,; source_file_captured= %a@," Typ.Procname.pp proc_name - SourceFile.pp source_file_captured ; if not (PredSymb.equal_access default.access access) then F.fprintf f "; access= %a@," (Pp.to_string ~f:PredSymb.string_of_access) access ; if not ([%compare.equal : (Mangled.t * Typ.t) list] default.captured captured) then @@ -224,8 +219,8 @@ let pp f (Pp.to_string ~f:string_of_clang_method_kind) clang_method_kind ; if not (Location.equal default.loc loc) then F.fprintf f "; loc= %a@," Location.pp loc ; - if not ([%compare.equal : SourceFile.t option] default.translation_unit translation_unit) then - F.fprintf f "; translation_unit= %a@," (Pp.option SourceFile.pp) translation_unit ; + if not ([%compare.equal : SourceFile.t] default.translation_unit translation_unit) then + F.fprintf f "; translation_unit= %a@," SourceFile.pp translation_unit ; if not ([%compare.equal : var_data list] default.locals locals) then F.fprintf f "; locals= [@[%a@]]@," (Pp.semicolon_seq ~print_env:Pp.text_break pp_var_data) diff --git a/infer/src/IR/ProcAttributes.mli b/infer/src/IR/ProcAttributes.mli index ab44dcec6..19eaff457 100644 --- a/infer/src/IR/ProcAttributes.mli +++ b/infer/src/IR/ProcAttributes.mli @@ -60,14 +60,13 @@ type t = ; is_synthetic_method: bool (** the procedure is a synthetic method *) ; clang_method_kind: clang_method_kind (** the kind of method the procedure is *) ; loc: Location.t (** location of this procedure in the source code *) - ; translation_unit: SourceFile.t option (** translation unit to which the procedure belongs *) + ; translation_unit: SourceFile.t (** translation unit to which the procedure belongs *) ; mutable locals: var_data list (** name, type and attributes of local variables *) ; method_annotation: Annot.Method.t (** annotations for all methods *) ; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *) ; proc_flags: proc_flags (** flags of the procedure *) ; proc_name: Typ.Procname.t (** name of the procedure *) - ; ret_type: Typ.t (** return type *) - ; source_file_captured: SourceFile.t (** source file where the procedure was captured *) } + ; ret_type: Typ.t (** return type *) } [@@deriving compare] val default : Typ.Procname.t -> t diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 3afc0352d..54d7fb73c 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -822,7 +822,7 @@ let specialize_with_block_args callee_pdesc pname_with_block_args block_args = in List.unzip new_formals_blocks_captured_vars_with_annots in - let source_file_captured = + let translation_unit = let pname = get_proc_name callee_pdesc in match Attributes.find_file_capturing_procedure pname with | Some (source_file, _) -> @@ -840,7 +840,7 @@ let specialize_with_block_args callee_pdesc pname_with_block_args block_args = ; err_log= Errlog.empty () ; formals= new_formals_blocks_captured_vars ; method_annotation= (fst callee_attributes.method_annotation, extended_formals_annots) - ; source_file_captured } + ; translation_unit } in Attributes.store resolved_attributes ; let resolved_pdesc = from_proc_attributes resolved_attributes in diff --git a/infer/src/backend/callbacks.ml b/infer/src/backend/callbacks.ml index 9e297422c..be4c6d267 100644 --- a/infer/src/backend/callbacks.ml +++ b/infer/src/backend/callbacks.ml @@ -97,12 +97,12 @@ let dump_duplicate_procs (exe_env: Exe_env.t) procs = match Exe_env.get_proc_desc exe_env pname with | Some pdesc when (* defined in the current file *) Procdesc.is_defined pdesc -> ( match Attributes.load pname with - | Some {source_file_captured; loc} + | Some {translation_unit; loc} when (* defined in another file *) - not (SourceFile.equal exe_env.source_file source_file_captured) + not (SourceFile.equal exe_env.source_file translation_unit) && (* really defined in the current file and not in an include *) SourceFile.equal exe_env.source_file loc.file -> - Some (pname, source_file_captured) + Some (pname, translation_unit) | _ -> None ) | _ -> diff --git a/infer/src/backend/exe_env.ml b/infer/src/backend/exe_env.ml index 4edddf151..7f574ce36 100644 --- a/infer/src/backend/exe_env.ml +++ b/infer/src/backend/exe_env.ml @@ -47,10 +47,10 @@ let get_file_data exe_env pname = L.(debug Analysis Medium) "can't find tenv_cfg_object for %a@." Typ.Procname.pp pname ; None | Some proc_attributes when Config.reactive_capture -> - let get_captured_file {ProcAttributes.source_file_captured} = source_file_captured in + let get_captured_file {ProcAttributes.translation_unit} = translation_unit in OndemandCapture.try_capture proc_attributes |> Option.map ~f:get_captured_file | Some proc_attributes -> - Some proc_attributes.ProcAttributes.source_file_captured + Some proc_attributes.ProcAttributes.translation_unit in let get_file_data_for_source source_file = let file_data = create_file_data exe_env.file_map source_file in diff --git a/infer/src/checkers/Siof.ml b/infer/src/checkers/Siof.ml index fbe8b6b10..dd5419a07 100644 --- a/infer/src/checkers/Siof.ml +++ b/infer/src/checkers/Siof.ml @@ -8,7 +8,6 @@ open! IStd open! AbstractDomain.Types module F = Format -module L = Logging module GlobalVar = SiofTrace.GlobalVar module GlobalVarSet = SiofTrace.GlobalVarSet @@ -193,14 +192,12 @@ end module Analyzer = AbstractInterpreter.Make (ProcCfg.Normal) (TransferFunctions) -let is_foreign tu_opt v = - match (Pvar.get_translation_unit v, tu_opt) with - | Some v_tu, Some current_tu -> +let is_foreign current_tu v = + match Pvar.get_translation_unit v with + | Some v_tu -> not (SourceFile.equal current_tu v_tu) - | None, Some _ -> + | None -> true - | _, None -> - L.(die InternalError) "cannot be called with translation unit set to None" let report_siof summary trace pdesc gname loc = @@ -237,13 +234,13 @@ let siof_check pdesc gname (summary: Summary.t) = match summary.payloads.siof with | Some (NonBottom post, _) -> let attrs = Procdesc.get_attributes pdesc in - let tu_opt = + let tu = let attrs = Procdesc.get_attributes pdesc in attrs.ProcAttributes.translation_unit in let foreign_sinks = SiofTrace.Sinks.filter - (fun sink -> SiofTrace.Sink.kind sink |> is_foreign tu_opt) + (fun sink -> SiofTrace.Sink.kind sink |> is_foreign tu) (SiofTrace.sinks post) in if not (SiofTrace.Sinks.is_empty foreign_sinks) then @@ -269,8 +266,7 @@ let checker {Callbacks.proc_desc; tenv; summary; get_procs_in_file} : Summary.t in get_procs_in_file pname |> List.exists ~f:(Typ.Procname.equal magic_iostream_marker) in - Option.value_map ~default:false ~f:includes_iostream - (Procdesc.get_attributes proc_desc).ProcAttributes.translation_unit + includes_iostream (Procdesc.get_attributes proc_desc).ProcAttributes.translation_unit in let proc_data = ProcData.make_default proc_desc tenv in let initial = diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 2d4683140..4ee1ee71b 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -265,6 +265,7 @@ let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg te let objc_property_accessor = if set_objc_accessor_attr then get_objc_property_accessor tenv ms else None in + let translation_unit = trans_unit_ctx.CFrontend_config.source_file in let procdesc = let proc_attributes = { (ProcAttributes.default proc_name) with @@ -280,7 +281,7 @@ let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg te ; loc= loc_start ; clang_method_kind ; objc_accessor= objc_property_accessor - ; translation_unit= Some trans_unit_ctx.CFrontend_config.source_file + ; translation_unit ; method_annotation ; ret_type } in