[clang] Make another crash into incorrect_assumption

Reviewed By: jvillard

Differential Revision: D6948348

fbshipit-source-id: 70a1227
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 14445fad05
commit 366f4f5ca2

@ -83,12 +83,17 @@ let rec get_curr_class context =
context.curr_class
let get_curr_class_decl_ptr curr_class =
match curr_class with ContextClsDeclPtr ptr -> ptr | _ -> assert false
let get_curr_class_decl_ptr stmt_info curr_class =
match curr_class with
| ContextClsDeclPtr ptr ->
ptr
| _ ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"current class is not ContextClsDeclPtr"
let get_curr_class_ptr curr_class =
let decl_ptr = get_curr_class_decl_ptr curr_class in
let get_curr_class_ptr stmt_info curr_class =
let decl_ptr = get_curr_class_decl_ptr stmt_info curr_class in
let get_ptr_from_decl_ref = function
| Some dr ->
dr.Clang_ast_t.dr_decl_pointer
@ -105,10 +110,10 @@ let get_curr_class_ptr curr_class =
decl_ptr
let get_curr_class_typename context =
let get_curr_class_typename stmt_info context =
let tenv = context.tenv in
let curr_class = get_curr_class context in
match get_curr_class_ptr curr_class |> CAst_utils.get_decl with
match get_curr_class_ptr stmt_info curr_class |> CAst_utils.get_decl with
| Some decl ->
CType_decl.get_record_typename ~tenv decl
| None ->

@ -40,9 +40,9 @@ val get_procdesc : t -> Procdesc.t
val get_curr_class : t -> curr_class
val get_curr_class_typename : t -> Typ.Name.t
val get_curr_class_typename : Clang_ast_t.stmt_info -> t -> Typ.Name.t
val get_curr_class_decl_ptr : curr_class -> Clang_ast_t.pointer
val get_curr_class_decl_ptr : Clang_ast_t.stmt_info -> curr_class -> Clang_ast_t.pointer
val is_objc_method : t -> bool

@ -674,13 +674,13 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
empty_res_trans
let get_this_exp_typ ?class_qual_type {CContext.curr_class; tenv; procdesc} =
let get_this_exp_typ stmt_info ?class_qual_type {CContext.curr_class; tenv; procdesc} =
let class_qual_type =
match class_qual_type with
| Some class_qual_type ->
class_qual_type
| None ->
let class_ptr = CContext.get_curr_class_decl_ptr curr_class in
let class_ptr = CContext.get_curr_class_decl_ptr stmt_info curr_class in
Ast_expressions.create_pointer_qual_type (CAst_utils.qual_type_of_decl_ptr class_ptr)
in
let procname = Procdesc.get_proc_name procdesc in
@ -689,8 +689,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
(Exp.Lvar pvar, CType_decl.qual_type_to_sil_type tenv class_qual_type)
let this_expr_trans ?class_qual_type trans_state sil_loc =
let exps = [get_this_exp_typ ?class_qual_type trans_state.context] in
let this_expr_trans stmt_info ?class_qual_type trans_state sil_loc =
let exps = [get_this_exp_typ stmt_info ?class_qual_type trans_state.context] in
(* there is no cast operation in AST, but backend needs it *)
dereference_value_from_result sil_loc {empty_res_trans with exps} ~strip_pointer:false
@ -699,7 +699,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let compute_this_expr trans_state stmt_info =
let context = trans_state.context in
let sil_loc = CLocation.get_sil_location stmt_info context in
let this_res_trans = this_expr_trans trans_state sil_loc in
let this_res_trans = this_expr_trans stmt_info trans_state sil_loc in
let obj_sil, class_typ =
extract_exp_from_list this_res_trans.exps
"WARNING: There should be one expression for 'this'. @\n"
@ -710,7 +710,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let cxxThisExpr_trans trans_state stmt_info expr_info =
let sil_loc = CLocation.get_sil_location stmt_info trans_state.context in
this_expr_trans trans_state sil_loc ~class_qual_type:expr_info.Clang_ast_t.ei_qual_type
this_expr_trans stmt_info trans_state sil_loc
~class_qual_type:expr_info.Clang_ast_t.ei_qual_type
let rec labelStmt_trans trans_state stmt_info stmt_list label_name =
@ -749,7 +750,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let var_exp = Exp.Lvar pvar in
let exps =
if Self.is_var_self pvar (CContext.is_objc_method context) then
let class_name = CContext.get_curr_class_typename context in
let class_name = CContext.get_curr_class_typename stmt_info context in
if CType.is_class typ then
raise
(Self.SelfClassException
@ -1264,7 +1265,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
get_callee_objc_method context obj_c_message_expr_info subexpr_exprs
in
let res_trans_add_self =
Self.add_self_parameter_for_super_instance context procname sil_loc
Self.add_self_parameter_for_super_instance si context procname sil_loc
obj_c_message_expr_info
in
let res_trans_subexpr_list = res_trans_add_self :: res_trans_subexpr_list in
@ -1315,7 +1316,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
empty_res_trans
else
(* get virtual base classes of the current class *)
let class_ptr = CContext.get_curr_class_decl_ptr context.CContext.curr_class in
let class_ptr = CContext.get_curr_class_decl_ptr stmt_info context.CContext.curr_class in
let decl = Option.value_exn (CAst_utils.get_decl class_ptr) in
let typ_pointer_opt = CAst_utils.type_of_decl decl in
let bases = CAst_utils.get_cxx_virtual_base_classes decl in
@ -1341,7 +1342,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
empty_res_trans
else
(* get fields and base classes of the current class *)
let class_ptr = CContext.get_curr_class_decl_ptr context.CContext.curr_class in
let class_ptr = CContext.get_curr_class_decl_ptr stmt_info context.CContext.curr_class in
let decl = Option.value_exn (CAst_utils.get_decl class_ptr) in
let fields = CAst_utils.get_record_fields decl in
let bases = CAst_utils.get_cxx_base_classes decl in
@ -3387,7 +3388,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
{(CAst_utils.dummy_stmt_info ()) with Clang_ast_t.si_source_range= source_range}
in
let trans_state' = PriorityNode.try_claim_priority_node trans_state this_stmt_info in
let this_res_trans = this_expr_trans trans_state' sil_loc in
let this_res_trans = this_expr_trans child_stmt_info trans_state' sil_loc in
let var_res_trans =
match ctor_init.Clang_ast_t.xci_subject with
| `Delegating _ | `BaseClass _ ->

@ -588,11 +588,12 @@ module Self = struct
; position: CFrontend_config.ocaml_pos
; source_range: Clang_ast_t.source_range }
let add_self_parameter_for_super_instance context procname loc mei =
let add_self_parameter_for_super_instance stmt_info context procname loc mei =
if is_superinstance mei then
let typ, self_expr, ins =
let t' =
CType.add_pointer_to_typ (Typ.mk (Tstruct (CContext.get_curr_class_typename context)))
CType.add_pointer_to_typ
(Typ.mk (Tstruct (CContext.get_curr_class_typename stmt_info context)))
in
let e = Exp.Lvar (Pvar.mk (Mangled.from_string CFrontend_config.self) procname) in
let id = Ident.create_fresh Ident.knormal in

@ -162,8 +162,8 @@ module Self : sig
; source_range: Clang_ast_t.source_range }
val add_self_parameter_for_super_instance :
CContext.t -> Typ.Procname.t -> Location.t -> Clang_ast_t.obj_c_message_expr_info
-> trans_result
Clang_ast_t.stmt_info -> CContext.t -> Typ.Procname.t -> Location.t
-> Clang_ast_t.obj_c_message_expr_info -> trans_result
val is_var_self : Pvar.t -> bool -> bool
end

Loading…
Cancel
Save