From 5ed50f5a9713e6c0e755e9f46c6bcfb6240b8257 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Fri, 22 Jul 2016 06:06:32 -0700 Subject: [PATCH] Keep more precise information in constructor's var_exp_typ Summary: No longer allow pointer types to be passed inside var_exp_typ. We used to accept both forms, but it won't be possible any longer once shared_ptr becomes pointer type. Reviewed By: dulmarod Differential Revision: D3593003 fbshipit-source-id: a830914 --- infer/src/clang/cTrans.ml | 14 +++++++------- .../frontend/constructors/constructor_new.cpp.dot | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index ce016941e..e26fbdfb7 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -957,10 +957,7 @@ struct let class_type = CTypes_decl.get_type_from_expr_info ei context.CContext.tenv in Cfg.Procdesc.append_locals procdesc [(Pvar.get_name pvar, class_type)]; Sil.Lvar pvar, class_type in - let this_type = - match class_type with - | Typ.Tptr _ -> class_type - | _ -> Typ.Tptr (class_type, Typ.Pk_pointer) in + let this_type = Typ.Tptr (class_type, Typ.Pk_pointer) in let this_res_trans = { empty_res_trans with exps = [(var_exp, this_type)]; initd_exps = [var_exp]; @@ -2028,9 +2025,10 @@ struct and initListExpr_initializers_trans trans_state var_exp n stmts typ is_dyn_array stmt_info = let (var_exp_inside, typ_inside) = match typ with - | Typ.Tarray (t, _) - | Typ.Tptr (t, _) when Typ.is_array_of_cpp_class typ || is_dyn_array -> + | Typ.Tarray (t, _) when Typ.is_array_of_cpp_class typ -> Sil.Lindex (var_exp, Sil.Const (Const.Cint (IntLit.of_int n))), t + | _ when is_dyn_array -> + Sil.Lindex (var_exp, Sil.Const (Const.Cint (IntLit.of_int n))), typ | _ -> var_exp, typ in let trans_state' = { trans_state with var_exp_typ = Some (var_exp_inside, typ_inside) } in match stmts with @@ -2086,7 +2084,9 @@ struct let res_trans_new = cpp_new_trans trans_state_pri sil_loc typ size_exp_opt in let stmt_opt = Ast_utils.get_stmt_opt cxx_new_expr_info.Clang_ast_t.xnei_initializer_expr in let trans_state_init = { trans_state_pri with succ_nodes = []; } in - let var_exp_typ = match res_trans_new.exps with [exp] -> exp | _ -> assert false in + let var_exp_typ = match res_trans_new.exps with + | [var_exp, Typ.Tptr (t, _)] -> (var_exp, t) + | _ -> assert false in (* Need a new stmt_info for the translation of the initializer, so that it can create nodes *) (* if it needs to, with the same stmt_info it doesn't work. *) let init_stmt_info = { stmt_info with diff --git a/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_new.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_new.cpp.dot index 689fa1b0c..257fda6ed 100644 --- a/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_new.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_new.cpp.dot @@ -217,7 +217,7 @@ digraph iCFG { 43 -> 54 ; -42 [label="42: DeclStmt \n n$2=_fun___new(sizeof(int ):unsigned long ) [line 58]\n *n$2:int *=0 [line 58]\n *&x1:int *=n$2 [line 58]\n " shape="box"] +42 [label="42: DeclStmt \n n$2=_fun___new(sizeof(int ):unsigned long ) [line 58]\n *n$2:int =0 [line 58]\n *&x1:int *=n$2 [line 58]\n " shape="box"] 42 -> 41 ;