Fix type of CXXThisExpr_trans

Summary: public
When method was called from within other method,
the type of `this` parameter didn't have pointer in type.
This was due to wrong logic that stripped pointer out of the
type.

We still need to strip the type when dereferencing reference variable.

Reviewed By: dulmarod

Differential Revision: D2652012

fb-gh-sync-id: 44552ac
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent f20af0e9aa
commit c4b237e9f6

@ -350,7 +350,7 @@ struct
let res_trans = { empty_res_trans with exps = exps } in let res_trans = { empty_res_trans with exps = exps } in
if CTypes.is_reference_type type_ptr then if CTypes.is_reference_type type_ptr then
(* dereference pvar due to the behavior of reference types in clang's AST *) (* dereference pvar due to the behavior of reference types in clang's AST *)
dereference_value_from_result sil_loc res_trans dereference_value_from_result sil_loc res_trans ~strip_pointer:true
else res_trans else res_trans
let field_deref_trans trans_state pre_trans_result decl_ref = let field_deref_trans trans_state pre_trans_result decl_ref =
@ -403,7 +403,7 @@ struct
let typ = CTypes_decl.type_ptr_to_sil_type context.CContext.tenv tp in let typ = CTypes_decl.type_ptr_to_sil_type context.CContext.tenv tp in
let exps = [(exp, typ)] in let exps = [(exp, typ)] in
(* there is no cast operation in AST, but backend needs it *) (* there is no cast operation in AST, but backend needs it *)
dereference_value_from_result sil_loc { empty_res_trans with exps = exps } dereference_value_from_result sil_loc { empty_res_trans with exps = exps } ~strip_pointer:false
let rec labelStmt_trans trans_state stmt_info stmt_list label_name = let rec labelStmt_trans trans_state stmt_info stmt_list label_name =
(* go ahead with the translation *) (* go ahead with the translation *)

@ -366,14 +366,15 @@ let dereference_var_sil (exp, typ) sil_loc =
(** Given trans_result with ONE expression, create temporary variable with *) (** Given trans_result with ONE expression, create temporary variable with *)
(** value of an expression assigned to it *) (** value of an expression assigned to it *)
let dereference_value_from_result sil_loc trans_result = let dereference_value_from_result sil_loc trans_result ~strip_pointer =
let (obj_sil, class_typ) = extract_exp_from_list trans_result.exps "" in let (obj_sil, class_typ) = extract_exp_from_list trans_result.exps "" in
let cast_ids, cast_inst, cast_exp = dereference_var_sil (obj_sil, class_typ) sil_loc in let cast_ids, cast_inst, cast_exp = dereference_var_sil (obj_sil, class_typ) sil_loc in
let typ_no_ptr = match class_typ with | Sil.Tptr (typ, _) -> typ | _ -> assert false in let typ_no_ptr = match class_typ with | Sil.Tptr (typ, _) -> typ | _ -> assert false in
let cast_typ = if strip_pointer then typ_no_ptr else class_typ in
{ trans_result with { trans_result with
ids = trans_result.ids @ cast_ids; ids = trans_result.ids @ cast_ids;
instrs = trans_result.instrs @ cast_inst; instrs = trans_result.instrs @ cast_inst;
exps = [(cast_exp, typ_no_ptr)] exps = [(cast_exp, cast_typ)]
} }

@ -77,7 +77,7 @@ val get_type_from_exp_stmt : Clang_ast_t.stmt -> Clang_ast_t.type_ptr
(** Given trans_result with ONE expression, create temporary variable with *) (** Given trans_result with ONE expression, create temporary variable with *)
(** dereferenced value of an expression assigned to it *) (** dereferenced value of an expression assigned to it *)
val dereference_value_from_result : Location.t -> trans_result -> trans_result val dereference_value_from_result : Location.t -> trans_result -> strip_pointer:bool -> trans_result
val cast_operation : val cast_operation :
CContext.t -> Clang_ast_t.cast_kind -> (Sil.exp * Sil.typ) list -> Sil.typ -> Location.t -> CContext.t -> Clang_ast_t.cast_kind -> (Sil.exp * Sil.typ) list -> Sil.typ -> Location.t ->

@ -48,7 +48,7 @@ digraph iCFG {
14 -> 13 ; 14 -> 13 ;
13 [label="13: Call _fun_X_init \n n$2=*&this:class X * [line 25]\n _fun_X_init(n$2:class X ) [line 25]\n REMOVE_TEMPS(n$2); [line 25]\n " shape="box"] 13 [label="13: Call _fun_X_init \n n$2=*&this:class X * [line 25]\n _fun_X_init(n$2:class X *) [line 25]\n REMOVE_TEMPS(n$2); [line 25]\n " shape="box"]
13 -> 12 ; 13 -> 12 ;
@ -74,7 +74,7 @@ digraph iCFG {
7 -> 9 ; 7 -> 9 ;
6 [label="6: Call _fun_X_init \n n$0=*&this:class X * [line 15]\n _fun_X_init(n$0:class X ) [line 15]\n REMOVE_TEMPS(n$0); [line 15]\n NULLIFY(&this,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"] 6 [label="6: Call _fun_X_init \n n$0=*&this:class X * [line 15]\n _fun_X_init(n$0:class X *) [line 15]\n REMOVE_TEMPS(n$0); [line 15]\n NULLIFY(&this,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"]
6 -> 5 ; 6 -> 5 ;

@ -10,7 +10,7 @@ digraph iCFG {
8 -> 10 ; 8 -> 10 ;
7 [label="7: Call _fun_A_init \n n$2=*&this:class A * [line 18]\n _fun_A_init(n$2:class A ,10:int ) [line 18]\n REMOVE_TEMPS(n$2); [line 18]\n " shape="box"] 7 [label="7: Call _fun_A_init \n n$2=*&this:class A * [line 18]\n _fun_A_init(n$2:class A *,10:int ) [line 18]\n REMOVE_TEMPS(n$2); [line 18]\n " shape="box"]
7 -> 6 ; 7 -> 6 ;

Loading…
Cancel
Save