diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 5f89438ea..f2e44ce85 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -350,7 +350,7 @@ struct let res_trans = { empty_res_trans with exps = exps } in if CTypes.is_reference_type type_ptr then (* 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 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 exps = [(exp, typ)] in (* 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 = (* go ahead with the translation *) diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index 038173d6b..4eccf0724 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -366,14 +366,15 @@ let dereference_var_sil (exp, typ) sil_loc = (** Given trans_result with ONE expression, create temporary variable with *) (** 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 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 cast_typ = if strip_pointer then typ_no_ptr else class_typ in { trans_result with ids = trans_result.ids @ cast_ids; instrs = trans_result.instrs @ cast_inst; - exps = [(cast_exp, typ_no_ptr)] + exps = [(cast_exp, cast_typ)] } diff --git a/infer/src/clang/cTrans_utils.mli b/infer/src/clang/cTrans_utils.mli index 443ba97ec..a04986f18 100644 --- a/infer/src/clang/cTrans_utils.mli +++ b/infer/src/clang/cTrans_utils.mli @@ -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 *) (** 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 : CContext.t -> Clang_ast_t.cast_kind -> (Sil.exp * Sil.typ) list -> Sil.typ -> Location.t -> diff --git a/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_with_body.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_with_body.cpp.dot index 430f3a158..ccb3a206d 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_with_body.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_with_body.cpp.dot @@ -48,7 +48,7 @@ digraph iCFG { 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 ; @@ -74,7 +74,7 @@ digraph iCFG { 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 ; diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/dereference_this.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/methods/dereference_this.cpp.dot index 8a62154b0..04b1aca2f 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/methods/dereference_this.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/dereference_this.cpp.dot @@ -10,7 +10,7 @@ digraph iCFG { 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 ;