From a317ac38f2578a75c5208e88898bf1d4e268475c Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Tue, 26 Jan 2016 07:24:14 -0800 Subject: [PATCH] Use init_exp in InitListExpr and CompoundLiteralExpr Summary: public Remove some of the explicit pattern matches in favor of using trans_state.var_exp for init lists and compound literals Reviewed By: jvillard Differential Revision: D2855203 fb-gh-sync-id: ce929f6 --- infer/src/clang/cTrans.ml | 18 ++++++++++-------- .../initialization/array_initlistexpr.c.dot | 2 +- .../initialization/compound_literal.c.dot | 4 ++-- .../initialization/struct_initlistexpr.c.dot | 4 ++-- .../objc/frontend/vardecl/initlist.dot | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 3f8a485e3..3e9408093 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -585,8 +585,9 @@ struct | [s1; ImplicitCastExpr (stmt, [CompoundLiteralExpr (cle_stmt_info, stmts, expr_info)], _, cast_expr_info)] -> let decl_ref = get_decl_ref_info s1 in let pvar = CVar_decl.sil_var_of_decl_ref context decl_ref procname in + let trans_state' = { trans_state with var_exp = Some (Sil.Lvar pvar) } in let res_trans_tmp = - initListExpr_trans trans_state (Sil.Lvar pvar) stmt_info expr_info stmts in + initListExpr_trans trans_state' stmt_info expr_info stmts in { res_trans_tmp with leaf_nodes =[]} | [s1; s2] -> (* Assumption: We expect precisely 2 stmt corresponding to the 2 operands*) let rhs_owning_method = CTrans_utils.is_owning_method s2 in @@ -1367,7 +1368,8 @@ struct let loop = Clang_ast_t.WhileStmt (stmt_info, [null_stmt; cond; body']) in instruction trans_state (Clang_ast_t.CompoundStmt (stmt_info, [assign_next_object; loop])) - and initListExpr_trans trans_state var_exp stmt_info expr_info stmts = + and initListExpr_trans trans_state stmt_info expr_info stmts = + let var_exp = match trans_state.var_exp with Some e -> e | _ -> assert false in let context = trans_state.context in let succ_nodes = trans_state.succ_nodes in let rec collect_right_hand_exprs ts stmt = match stmt with @@ -1473,10 +1475,6 @@ struct | [] -> () | _ -> Printing.log_stats "\n!!!!WARNING: found statement <\"ImplicitValueInitExpr\"> with non-empty stmt_list.\n"); { empty_res_trans with root_nodes = trans_state.succ_nodes } - | Some (InitListExpr (stmt_info , stmts , expr_info)) - | Some (ImplicitCastExpr (_, [CompoundLiteralExpr (_, [InitListExpr (stmt_info , stmts , expr_info)], _)], _, _)) - | Some (ExprWithCleanups (_, [InitListExpr (stmt_info , stmts , expr_info)], _, _)) -> - initListExpr_trans trans_state var_exp stmt_info expr_info stmts | Some ie -> (*For init expr, translate how to compute it and assign to the var*) let stmt_info, _ = Clang_ast_proj.get_stmt_tuple ie in let context = trans_state.context in @@ -1848,7 +1846,9 @@ struct let (pvar, typ) = mk_temp_sil_var_for_expr context.CContext.tenv procdesc "SIL_compound_literal__" expr_info in Cfg.Procdesc.append_locals procdesc [(Sil.pvar_get_name pvar, typ)]; - initListExpr_trans trans_state (Sil.Lvar pvar) stmt_info expr_info stmt_list + let trans_state' = { trans_state with var_exp = Some (Sil.Lvar pvar) } in + let stmt = match stmt_list with [stmt] -> stmt | _ -> assert false in + instruction trans_state' stmt (* Translates a clang instruction into SIL instructions. It takes a *) (* a trans_state containing current info on the translation and it returns *) @@ -2068,8 +2068,10 @@ struct cxxDeleteExpr_trans trans_state stmt_info stmt_list expr_info delete_expr_info | MaterializeTemporaryExpr (stmt_info, stmt_list, expr_info, _) -> materializeTemporaryExpr_trans trans_state stmt_info stmt_list expr_info - | CompoundLiteralExpr (_, [InitListExpr (stmt_info , stmt_list , expr_info)], _) -> + | CompoundLiteralExpr (stmt_info, stmt_list, expr_info) -> compoundLiteralExpr_trans trans_state stmt_info stmt_list expr_info + | InitListExpr (stmt_info, stmts, expr_info) -> + initListExpr_trans trans_state stmt_info expr_info stmts | s -> (Printing.log_stats "\n!!!!WARNING: found statement %s. \nACTION REQUIRED: Translation need to be defined. Statement ignored.... \n" (Ast_utils.string_of_stmt s); diff --git a/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot b/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot index 3481d8f7d..9f5b11e1a 100644 --- a/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot @@ -1,5 +1,5 @@ digraph iCFG { -3 [label="3: InitListExp \n n$0=*&z:int [line 12]\n *&a[0][0]:int =(n$0 + 1) [line 12]\n *&a[0][1]:int =2 [line 12]\n *&a[0][2]:int =3 [line 12]\n *&a[1][0]:int =5 [line 12]\n *&a[1][1]:int =6 [line 12]\n *&a[1][2]:int =7 [line 12]\n REMOVE_TEMPS(n$0); [line 12]\n NULLIFY(&z,false); [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"] +3 [label="3: DeclStmt \n n$0=*&z:int [line 12]\n *&a[0][0]:int =(n$0 + 1) [line 12]\n *&a[0][1]:int =2 [line 12]\n *&a[0][2]:int =3 [line 12]\n *&a[1][0]:int =5 [line 12]\n *&a[1][1]:int =6 [line 12]\n *&a[1][2]:int =7 [line 12]\n REMOVE_TEMPS(n$0); [line 12]\n NULLIFY(&z,false); [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"] 3 -> 2 ; diff --git a/infer/tests/codetoanalyze/c/frontend/initialization/compound_literal.c.dot b/infer/tests/codetoanalyze/c/frontend/initialization/compound_literal.c.dot index e070c8389..b92a9e00e 100644 --- a/infer/tests/codetoanalyze/c/frontend/initialization/compound_literal.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/initialization/compound_literal.c.dot @@ -1,5 +1,5 @@ digraph iCFG { -7 [label="7: InitListExp \n *&p.x:int =32 [line 20]\n *&p.y:int =52 [line 20]\n " shape="box"] +7 [label="7: DeclStmt \n *&SIL_compound_literal__n$1.x:int =32 [line 20]\n *&SIL_compound_literal__n$1.y:int =52 [line 20]\n n$2=*&SIL_compound_literal__n$1:struct point [line 20]\n *&p:struct point =n$2 [line 20]\n REMOVE_TEMPS(n$2); [line 20]\n NULLIFY(&SIL_compound_literal__n$1,false); [line 20]\n " shape="box"] 7 -> 6 ; @@ -10,7 +10,7 @@ digraph iCFG { 5 [label="5: Exit init_with_compound_literal \n " color=yellow style=filled] -4 [label="4: Start init_with_compound_literal\nFormals: \nLocals: p:struct point \n DECLARE_LOCALS(&return,&p); [line 19]\n " color=yellow style=filled] +4 [label="4: Start init_with_compound_literal\nFormals: \nLocals: p:struct point SIL_compound_literal__n$1:struct point \n DECLARE_LOCALS(&return,&p,&SIL_compound_literal__n$1); [line 19]\n NULLIFY(&p,false); [line 19]\n " color=yellow style=filled] 4 -> 7 ; diff --git a/infer/tests/codetoanalyze/c/frontend/initialization/struct_initlistexpr.c.dot b/infer/tests/codetoanalyze/c/frontend/initialization/struct_initlistexpr.c.dot index 5869ccb12..c075a180b 100644 --- a/infer/tests/codetoanalyze/c/frontend/initialization/struct_initlistexpr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/initialization/struct_initlistexpr.c.dot @@ -1,5 +1,5 @@ digraph iCFG { -14 [label="14: InitListExp \n *&e.doj.date:int =12 [line 41]\n *&e.doj.month:int =3000.500000 [line 41]\n *&e.doj.year:int =12 [line 41]\n *&e.salary:float =12 [line 41]\n *&e.ssn:int =2010 [line 41]\n " shape="box"] +14 [label="14: DeclStmt \n *&e.doj.date:int =12 [line 41]\n *&e.doj.month:int =3000.500000 [line 41]\n *&e.doj.year:int =12 [line 41]\n *&e.salary:float =12 [line 41]\n *&e.ssn:int =2010 [line 41]\n " shape="box"] 14 -> 13 ; @@ -29,7 +29,7 @@ digraph iCFG { 7 -> 10 ; -6 [label="6: InitListExp \n n$0=_fun_foo() [line 20]\n *&p.x:int =1 [line 20]\n *&p.y:int =(n$0 + 3) [line 20]\n REMOVE_TEMPS(n$0); [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] +6 [label="6: DeclStmt \n n$0=_fun_foo() [line 20]\n *&p.x:int =1 [line 20]\n *&p.y:int =(n$0 + 3) [line 20]\n REMOVE_TEMPS(n$0); [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] 6 -> 5 ; diff --git a/infer/tests/codetoanalyze/objc/frontend/vardecl/initlist.dot b/infer/tests/codetoanalyze/objc/frontend/vardecl/initlist.dot index d82410fa3..a9600564e 100644 --- a/infer/tests/codetoanalyze/objc/frontend/vardecl/initlist.dot +++ b/infer/tests/codetoanalyze/objc/frontend/vardecl/initlist.dot @@ -7,7 +7,7 @@ digraph iCFG { 7 -> 6 ; -6 [label="6: InitListExp \n n$0=*&c1:class C * [line 24]\n n$1=_fun_NSObject_init(n$0:class C *) virtual [line 24]\n n$2=*&c1:class C * [line 24]\n n$3=*&c2:class C * [line 24]\n *&a[0]:class C *=n$1 [line 24]\n _fun___objc_retain(n$2:class C *) [line 24]\n *&a[1]:class C *=n$2 [line 24]\n _fun___objc_retain(n$3:class C *) [line 24]\n *&a[2]:class C *=n$3 [line 24]\n REMOVE_TEMPS(n$0,n$1,n$2,n$3); [line 24]\n NULLIFY(&c1,false); [line 24]\n NULLIFY(&c2,false); [line 24]\n APPLY_ABSTRACTION; [line 24]\n " shape="box"] +6 [label="6: DeclStmt \n n$0=*&c1:class C * [line 24]\n n$1=_fun_NSObject_init(n$0:class C *) virtual [line 24]\n n$2=*&c1:class C * [line 24]\n n$3=*&c2:class C * [line 24]\n *&a[0]:class C *=n$1 [line 24]\n _fun___objc_retain(n$2:class C *) [line 24]\n *&a[1]:class C *=n$2 [line 24]\n _fun___objc_retain(n$3:class C *) [line 24]\n *&a[2]:class C *=n$3 [line 24]\n REMOVE_TEMPS(n$0,n$1,n$2,n$3); [line 24]\n NULLIFY(&c1,false); [line 24]\n NULLIFY(&c2,false); [line 24]\n APPLY_ABSTRACTION; [line 24]\n " shape="box"] 6 -> 5 ; @@ -18,7 +18,7 @@ digraph iCFG { 4 -> 8 ; -3 [label="3: InitListExp \n n$0=*&z:int [line 14]\n *&a[0][0]:int =(n$0 + 1) [line 14]\n *&a[0][1]:int =2 [line 14]\n *&a[0][2]:int =3 [line 14]\n *&a[1][0]:int =5 [line 14]\n *&a[1][1]:int =6 [line 14]\n *&a[1][2]:int =7 [line 14]\n REMOVE_TEMPS(n$0); [line 14]\n NULLIFY(&z,false); [line 14]\n APPLY_ABSTRACTION; [line 14]\n " shape="box"] +3 [label="3: DeclStmt \n n$0=*&z:int [line 14]\n *&a[0][0]:int =(n$0 + 1) [line 14]\n *&a[0][1]:int =2 [line 14]\n *&a[0][2]:int =3 [line 14]\n *&a[1][0]:int =5 [line 14]\n *&a[1][1]:int =6 [line 14]\n *&a[1][2]:int =7 [line 14]\n REMOVE_TEMPS(n$0); [line 14]\n NULLIFY(&z,false); [line 14]\n APPLY_ABSTRACTION; [line 14]\n " shape="box"] 3 -> 2 ;