[IR] Unify the proc attribute translation_unit and source_captured

Reviewed By: mbouaziz

Differential Revision: D8418447

fbshipit-source-id: 9d82c4b
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 35fba2de40
commit 2f00ccb434

@ -135,7 +135,7 @@ let load_defined pname = Typ.Procname.SQLite.serialize pname |> find ~defined:tr
let find_file_capturing_procedure pname = let find_file_capturing_procedure pname =
Option.map (load pname) ~f:(fun proc_attributes -> 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 = let origin =
(* Procedure coming from include files if it has different location than the file where it (* Procedure coming from include files if it has different location than the file where it
was captured. *) was captured. *)

@ -73,7 +73,7 @@ let save_attributes source_file cfg =
let loc = attributes.loc in let loc = attributes.loc in
let attributes' = let attributes' =
let loc' = if Location.equal loc Location.dummy then {loc with file= source_file} else loc in 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 in
Attributes.store attributes' Attributes.store attributes'
in in

@ -103,14 +103,13 @@ type t =
; is_synthetic_method: bool (** the procedure is a synthetic method *) ; is_synthetic_method: bool (** the procedure is a synthetic method *)
; clang_method_kind: clang_method_kind (** the kind of method the procedure is *) ; clang_method_kind: clang_method_kind (** the kind of method the procedure is *)
; loc: Location.t (** location of this procedure in the source code *) ; 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 *) ; mutable locals: var_data list (** name, type and attributes of local variables *)
; method_annotation: Annot.Method.t (** annotations for all methods *) ; method_annotation: Annot.Method.t (** annotations for all methods *)
; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *) ; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *)
; proc_flags: proc_flags (** flags of the procedure *) ; proc_flags: proc_flags (** flags of the procedure *)
; proc_name: Typ.Procname.t (** name of the procedure *) ; proc_name: Typ.Procname.t (** name of the procedure *)
; ret_type: Typ.t (** return type *) ; ret_type: Typ.t (** return type *) }
; source_file_captured: SourceFile.t (** source file where the procedure was captured *) }
[@@deriving compare] [@@deriving compare]
let default proc_name = let default proc_name =
@ -133,14 +132,13 @@ let default proc_name =
; is_synthetic_method= false ; is_synthetic_method= false
; clang_method_kind= C_FUNCTION ; clang_method_kind= C_FUNCTION
; loc= Location.dummy ; loc= Location.dummy
; translation_unit= None ; translation_unit= SourceFile.invalid __FILE__
; locals= [] ; locals= []
; method_annotation= Annot.Method.empty ; method_annotation= Annot.Method.empty
; objc_accessor= None ; objc_accessor= None
; proc_flags= proc_flags_empty () ; proc_flags= proc_flags_empty ()
; proc_name ; proc_name
; ret_type= Typ.mk Typ.Tvoid ; ret_type= Typ.mk Typ.Tvoid }
; source_file_captured= SourceFile.invalid __FILE__ }
let pp_parameters = let pp_parameters =
@ -173,14 +171,11 @@ let pp f
; objc_accessor ; objc_accessor
; proc_flags ; proc_flags
; proc_name ; proc_name
; ret_type ; ret_type }[@warning "+9"]) =
; source_file_captured }[@warning "+9"]) =
let default = default proc_name in let default = default proc_name in
let pp_bool_default ~default title b f () = let pp_bool_default ~default title b f () =
if not (Bool.equal default b) then F.fprintf f "; %s= %b@," title b if not (Bool.equal default b) then F.fprintf f "; %s= %b@," title b
in in
F.fprintf f "@[<v>{ 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 if not (PredSymb.equal_access default.access access) then
F.fprintf f "; access= %a@," (Pp.to_string ~f:PredSymb.string_of_access) access ; 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 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) (Pp.to_string ~f:string_of_clang_method_kind)
clang_method_kind ; clang_method_kind ;
if not (Location.equal default.loc loc) then F.fprintf f "; loc= %a@," Location.pp loc ; 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 if not ([%compare.equal : SourceFile.t] default.translation_unit translation_unit) then
F.fprintf f "; translation_unit= %a@," (Pp.option SourceFile.pp) translation_unit ; F.fprintf f "; translation_unit= %a@," SourceFile.pp translation_unit ;
if not ([%compare.equal : var_data list] default.locals locals) then if not ([%compare.equal : var_data list] default.locals locals) then
F.fprintf f "; locals= [@[%a@]]@," F.fprintf f "; locals= [@[%a@]]@,"
(Pp.semicolon_seq ~print_env:Pp.text_break pp_var_data) (Pp.semicolon_seq ~print_env:Pp.text_break pp_var_data)

@ -60,14 +60,13 @@ type t =
; is_synthetic_method: bool (** the procedure is a synthetic method *) ; is_synthetic_method: bool (** the procedure is a synthetic method *)
; clang_method_kind: clang_method_kind (** the kind of method the procedure is *) ; clang_method_kind: clang_method_kind (** the kind of method the procedure is *)
; loc: Location.t (** location of this procedure in the source code *) ; 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 *) ; mutable locals: var_data list (** name, type and attributes of local variables *)
; method_annotation: Annot.Method.t (** annotations for all methods *) ; method_annotation: Annot.Method.t (** annotations for all methods *)
; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *) ; objc_accessor: objc_accessor_type option (** type of ObjC accessor, if any *)
; proc_flags: proc_flags (** flags of the procedure *) ; proc_flags: proc_flags (** flags of the procedure *)
; proc_name: Typ.Procname.t (** name of the procedure *) ; proc_name: Typ.Procname.t (** name of the procedure *)
; ret_type: Typ.t (** return type *) ; ret_type: Typ.t (** return type *) }
; source_file_captured: SourceFile.t (** source file where the procedure was captured *) }
[@@deriving compare] [@@deriving compare]
val default : Typ.Procname.t -> t val default : Typ.Procname.t -> t

@ -822,7 +822,7 @@ let specialize_with_block_args callee_pdesc pname_with_block_args block_args =
in in
List.unzip new_formals_blocks_captured_vars_with_annots List.unzip new_formals_blocks_captured_vars_with_annots
in in
let source_file_captured = let translation_unit =
let pname = get_proc_name callee_pdesc in let pname = get_proc_name callee_pdesc in
match Attributes.find_file_capturing_procedure pname with match Attributes.find_file_capturing_procedure pname with
| Some (source_file, _) -> | Some (source_file, _) ->
@ -840,7 +840,7 @@ let specialize_with_block_args callee_pdesc pname_with_block_args block_args =
; err_log= Errlog.empty () ; err_log= Errlog.empty ()
; formals= new_formals_blocks_captured_vars ; formals= new_formals_blocks_captured_vars
; method_annotation= (fst callee_attributes.method_annotation, extended_formals_annots) ; method_annotation= (fst callee_attributes.method_annotation, extended_formals_annots)
; source_file_captured } ; translation_unit }
in in
Attributes.store resolved_attributes ; Attributes.store resolved_attributes ;
let resolved_pdesc = from_proc_attributes resolved_attributes in let resolved_pdesc = from_proc_attributes resolved_attributes in

@ -97,12 +97,12 @@ let dump_duplicate_procs (exe_env: Exe_env.t) procs =
match Exe_env.get_proc_desc exe_env pname with match Exe_env.get_proc_desc exe_env pname with
| Some pdesc when (* defined in the current file *) Procdesc.is_defined pdesc -> ( | Some pdesc when (* defined in the current file *) Procdesc.is_defined pdesc -> (
match Attributes.load pname with match Attributes.load pname with
| Some {source_file_captured; loc} | Some {translation_unit; loc}
when (* defined in another file *) 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 *) && (* really defined in the current file and not in an include *)
SourceFile.equal exe_env.source_file loc.file -> SourceFile.equal exe_env.source_file loc.file ->
Some (pname, source_file_captured) Some (pname, translation_unit)
| _ -> | _ ->
None ) None )
| _ -> | _ ->

@ -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 ; L.(debug Analysis Medium) "can't find tenv_cfg_object for %a@." Typ.Procname.pp pname ;
None None
| Some proc_attributes when Config.reactive_capture -> | 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 OndemandCapture.try_capture proc_attributes |> Option.map ~f:get_captured_file
| Some proc_attributes -> | Some proc_attributes ->
Some proc_attributes.ProcAttributes.source_file_captured Some proc_attributes.ProcAttributes.translation_unit
in in
let get_file_data_for_source source_file = let get_file_data_for_source source_file =
let file_data = create_file_data exe_env.file_map source_file in let file_data = create_file_data exe_env.file_map source_file in

@ -8,7 +8,6 @@
open! IStd open! IStd
open! AbstractDomain.Types open! AbstractDomain.Types
module F = Format module F = Format
module L = Logging
module GlobalVar = SiofTrace.GlobalVar module GlobalVar = SiofTrace.GlobalVar
module GlobalVarSet = SiofTrace.GlobalVarSet module GlobalVarSet = SiofTrace.GlobalVarSet
@ -193,14 +192,12 @@ end
module Analyzer = AbstractInterpreter.Make (ProcCfg.Normal) (TransferFunctions) module Analyzer = AbstractInterpreter.Make (ProcCfg.Normal) (TransferFunctions)
let is_foreign tu_opt v = let is_foreign current_tu v =
match (Pvar.get_translation_unit v, tu_opt) with match Pvar.get_translation_unit v with
| Some v_tu, Some current_tu -> | Some v_tu ->
not (SourceFile.equal current_tu v_tu) not (SourceFile.equal current_tu v_tu)
| None, Some _ -> | None ->
true true
| _, None ->
L.(die InternalError) "cannot be called with translation unit set to None"
let report_siof summary trace pdesc gname loc = 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 match summary.payloads.siof with
| Some (NonBottom post, _) -> | Some (NonBottom post, _) ->
let attrs = Procdesc.get_attributes pdesc in let attrs = Procdesc.get_attributes pdesc in
let tu_opt = let tu =
let attrs = Procdesc.get_attributes pdesc in let attrs = Procdesc.get_attributes pdesc in
attrs.ProcAttributes.translation_unit attrs.ProcAttributes.translation_unit
in in
let foreign_sinks = let foreign_sinks =
SiofTrace.Sinks.filter 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) (SiofTrace.sinks post)
in in
if not (SiofTrace.Sinks.is_empty foreign_sinks) then 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 in
get_procs_in_file pname |> List.exists ~f:(Typ.Procname.equal magic_iostream_marker) get_procs_in_file pname |> List.exists ~f:(Typ.Procname.equal magic_iostream_marker)
in in
Option.value_map ~default:false ~f:includes_iostream includes_iostream (Procdesc.get_attributes proc_desc).ProcAttributes.translation_unit
(Procdesc.get_attributes proc_desc).ProcAttributes.translation_unit
in in
let proc_data = ProcData.make_default proc_desc tenv in let proc_data = ProcData.make_default proc_desc tenv in
let initial = let initial =

@ -265,6 +265,7 @@ let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg te
let objc_property_accessor = let objc_property_accessor =
if set_objc_accessor_attr then get_objc_property_accessor tenv ms else None if set_objc_accessor_attr then get_objc_property_accessor tenv ms else None
in in
let translation_unit = trans_unit_ctx.CFrontend_config.source_file in
let procdesc = let procdesc =
let proc_attributes = let proc_attributes =
{ (ProcAttributes.default proc_name) with { (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 ; loc= loc_start
; clang_method_kind ; clang_method_kind
; objc_accessor= objc_property_accessor ; objc_accessor= objc_property_accessor
; translation_unit= Some trans_unit_ctx.CFrontend_config.source_file ; translation_unit
; method_annotation ; method_annotation
; ret_type } ; ret_type }
in in

Loading…
Cancel
Save