[attributes] always have a (single) translation unit

Summary: Do not start with an invalid source file when we can avoid it. Follow up from D8418447.

Reviewed By: jeremydubreil

Differential Revision: D8732168

fbshipit-source-id: 28a183b
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 6f3719f5f2
commit 86e79a7125

@ -113,7 +113,7 @@ type t =
; ret_type: Typ.t (** return type *) }
[@@deriving compare]
let default proc_name =
let default translation_unit proc_name =
{ access= PredSymb.Default
; captured= []
; did_preanalysis= false
@ -134,7 +134,7 @@ let default proc_name =
; is_variadic= false
; clang_method_kind= C_FUNCTION
; loc= Location.dummy
; translation_unit= SourceFile.invalid __FILE__
; translation_unit
; locals= []
; method_annotation= Annot.Method.empty
; objc_accessor= None
@ -175,10 +175,12 @@ let pp f
; proc_flags
; proc_name
; ret_type }[@warning "+9"]) =
let default = default proc_name in
let default = default translation_unit 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 "@[<v>{ proc_name= %a@,; translation_unit= %a@," Typ.Procname.pp proc_name
SourceFile.pp translation_unit ;
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
@ -223,8 +225,6 @@ 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] 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)

@ -61,7 +61,7 @@ type t =
; is_variadic: bool (** the procedure is variadic, only supported for Clang procedures *)
; 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 (** translation unit to which the procedure belongs *)
; translation_unit: SourceFile.t (** source file where the procedure was captured *)
; 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 *)
@ -70,7 +70,7 @@ type t =
; ret_type: Typ.t (** return type *) }
[@@deriving compare]
val default : Typ.Procname.t -> t
val default : SourceFile.t -> Typ.Procname.t -> t
(** Create a proc_attributes with default values. *)
val pp : Format.formatter -> t -> unit

@ -249,7 +249,9 @@ let init_summary proc_desc =
let dummy =
let dummy_attributes = ProcAttributes.default Typ.Procname.empty_block in
let dummy_attributes =
ProcAttributes.default (SourceFile.invalid __FILE__) Typ.Procname.empty_block
in
let dummy_proc_desc = Procdesc.from_proc_attributes dummy_attributes in
init_summary dummy_proc_desc

@ -52,7 +52,7 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron
let recover () =
Typ.Procname.Hash.remove cfg procname ;
let method_kind = ms.CMethodSignature.method_kind in
CMethod_trans.create_external_procdesc cfg procname method_kind None
CMethod_trans.create_external_procdesc trans_unit_ctx cfg procname method_kind None
in
let pp_context fmt () =
F.fprintf fmt "Aborting translation of method '%a' in file '%a'" Typ.Procname.pp procname

@ -268,7 +268,7 @@ let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg te
let translation_unit = trans_unit_ctx.CFrontend_config.source_file in
let procdesc =
let proc_attributes =
{ (ProcAttributes.default proc_name) with
{ (ProcAttributes.default translation_unit proc_name) with
ProcAttributes.captured= captured_mangled
; formals
; const_formals
@ -282,7 +282,6 @@ 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
; method_annotation
; ret_type }
in
@ -302,7 +301,7 @@ let create_local_procdesc ?(set_objc_accessor_attr= false) trans_unit_ctx cfg te
(** Create a procdesc for objc methods whose signature cannot be found. *)
let create_external_procdesc cfg proc_name clang_method_kind type_opt =
let create_external_procdesc trans_unit_ctx cfg proc_name clang_method_kind type_opt =
if not (Typ.Procname.Hash.mem cfg proc_name) then
let ret_type, formals =
match type_opt with
@ -312,7 +311,8 @@ let create_external_procdesc cfg proc_name clang_method_kind type_opt =
(Typ.mk Typ.Tvoid, [])
in
let proc_attributes =
{(ProcAttributes.default proc_name) with ProcAttributes.formals; clang_method_kind; ret_type}
{ (ProcAttributes.default trans_unit_ctx.CFrontend_config.source_file proc_name) with
ProcAttributes.formals; clang_method_kind; ret_type }
in
ignore (Cfg.create_proc_desc cfg proc_attributes)
@ -335,7 +335,8 @@ let create_procdesc_with_pointer context pointer class_name_opt name =
( CType_decl.CProcname.NoAstDecl.c_function_of_string context.tenv name
, ProcAttributes.C_FUNCTION )
in
create_external_procdesc context.cfg callee_name method_kind None ;
create_external_procdesc context.translation_unit_context context.cfg callee_name method_kind
None ;
callee_name

@ -23,8 +23,8 @@ val create_local_procdesc :
-> CMethodSignature.t -> Clang_ast_t.stmt list -> (Pvar.t * Typ.t) list -> bool
val create_external_procdesc :
Cfg.t -> Typ.Procname.t -> ProcAttributes.clang_method_kind -> (Typ.t * Typ.t list) option
-> unit
CFrontend_config.translation_unit_context -> Cfg.t -> Typ.Procname.t
-> ProcAttributes.clang_method_kind -> (Typ.t * Typ.t list) option -> unit
val get_objc_method_data :
Clang_ast_t.obj_c_message_expr_info -> string * Clang_ast_t.pointer option * method_call_type

@ -73,7 +73,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
(proc_name, CMethod_trans.MCNoVirtual)
else (proc_name, mc_type)
| _ ->
CMethod_trans.create_external_procdesc context.cfg proc_name method_kind None ;
CMethod_trans.create_external_procdesc context.translation_unit_context context.cfg
proc_name method_kind None ;
(proc_name, mc_type)

@ -378,7 +378,8 @@ let objc_new_trans trans_state ~alloc_builtin loc stmt_info cls_name function_ty
CType_decl.CProcname.NoAstDecl.objc_method_of_string_kind cls_name CFrontend_config.init
Typ.Procname.ObjC_Cpp.ObjCInstanceMethod
in
CMethod_trans.create_external_procdesc trans_state.context.CContext.cfg pname method_kind None ;
CMethod_trans.create_external_procdesc trans_state.context.CContext.translation_unit_context
trans_state.context.CContext.cfg pname method_kind None ;
let args = [(alloc_ret_exp, alloc_ret_type)] in
let ret_id_typ = (init_ret_id, alloc_ret_type) in
let init_stmt_call =

@ -552,7 +552,8 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get
in
let ret_type = Typ.Procname.Java.get_return_typ callee_pname_java in
let proc_attributes =
{(ProcAttributes.default callee_pname) with ProcAttributes.formals; ret_type}
{ (ProcAttributes.default (SourceFile.invalid __FILE__) callee_pname) with
ProcAttributes.formals; ret_type }
in
proc_attributes
in

@ -301,8 +301,11 @@ let create_callee_attributes tenv program cn ms procname =
, List.map ~f:JBasics.cn_name cm.Javalib.cm_exceptions
, false )
in
(* getting the correct path to the source is cumbersome to do here, and nothing uses this data
yet so ignore this issue *)
let translation_unit = SourceFile.invalid __FILE__ in
Some
{ (ProcAttributes.default procname) with
{ (ProcAttributes.default translation_unit procname) with
ProcAttributes.access; exceptions; method_annotation; formals; ret_type; is_abstract }
with Caml.Not_found -> None
in
@ -328,7 +331,7 @@ let create_am_procdesc source_file program icfg am proc_name : Procdesc.t =
let method_annotation = JAnnotation.translate_method am.Javalib.am_annotations in
let procdesc =
let proc_attributes =
{ (ProcAttributes.default proc_name) with
{ (ProcAttributes.default source_file proc_name) with
ProcAttributes.access= trans_access am.Javalib.am_access
; exceptions= List.map ~f:JBasics.cn_name am.Javalib.am_exceptions
; formals
@ -353,7 +356,7 @@ let create_native_procdesc source_file program icfg cm proc_name =
let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in
let procdesc =
let proc_attributes =
{ (ProcAttributes.default proc_name) with
{ (ProcAttributes.default source_file proc_name) with
ProcAttributes.access= trans_access cm.Javalib.cm_access
; exceptions= List.map ~f:JBasics.cn_name cm.Javalib.cm_exceptions
; formals
@ -380,7 +383,7 @@ let create_empty_procdesc source_file program linereader icfg cm proc_name =
let formals = formals_from_signature program tenv cn ms (JTransType.get_method_kind m) in
let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in
let proc_attributes =
{ (ProcAttributes.default proc_name) with
{ (ProcAttributes.default source_file proc_name) with
ProcAttributes.access= trans_access cm.Javalib.cm_access
; exceptions= List.map ~f:JBasics.cn_name cm.Javalib.cm_exceptions
; formals
@ -417,7 +420,7 @@ let create_cm_procdesc source_file program linereader icfg cm proc_name =
in
let method_annotation = JAnnotation.translate_method cm.Javalib.cm_annotations in
let proc_attributes =
{ (ProcAttributes.default proc_name) with
{ (ProcAttributes.default source_file proc_name) with
ProcAttributes.access= trans_access cm.Javalib.cm_access
; exceptions= List.map ~f:JBasics.cn_name cm.Javalib.cm_exceptions
; formals

@ -155,7 +155,9 @@ struct
let structured_program_to_cfg program test_pname =
let cfg = Cfg.create () in
let pdesc = Cfg.create_proc_desc cfg (ProcAttributes.default test_pname) in
let pdesc =
Cfg.create_proc_desc cfg (ProcAttributes.default (SourceFile.invalid __FILE__) test_pname)
in
let pname = Procdesc.get_proc_name pdesc in
let create_node kind cmds = Procdesc.create_node pdesc dummy_loc kind cmds in
let set_succs cur_node succs ~exn_handlers =

@ -13,7 +13,10 @@ module BackwardInstrCfg = ProcCfg.Backward (InstrCfg)
let tests =
let cfg = Cfg.create () in
let test_pdesc = Cfg.create_proc_desc cfg (ProcAttributes.default Typ.Procname.empty_block) in
let test_pdesc =
Cfg.create_proc_desc cfg
(ProcAttributes.default (SourceFile.invalid __FILE__) Typ.Procname.empty_block)
in
let dummy_instr1 = Sil.Remove_temps ([], Location.dummy) in
let dummy_instr2 = Sil.Abstract Location.dummy in
let dummy_instr3 = Sil.Remove_temps ([Ident.create_fresh Ident.knormal], Location.dummy) in

Loading…
Cancel
Save