Translate constructor initializer

Summary:
public
Don't skip constructor init list anymore.

Reviewed By: jberdine

Differential Revision: D2895364

fb-gh-sync-id: 4bd8139
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent 1d6aea0fb9
commit 359ad9dd4b

@ -521,20 +521,21 @@ struct
| Some decl_ref -> method_deref_trans trans_state pvar_trans_result decl_ref
| None -> empty_res_trans
let cxxThisExpr_trans trans_state stmt_info expr_info =
let this_expr_trans trans_state sil_loc class_type_ptr =
let context = trans_state.context in
let sil_loc = CLocation.get_sil_location stmt_info context in
let tp = expr_info.Clang_ast_t.ei_type_ptr in
let procname = Cfg.Procdesc.get_proc_name context.CContext.procdesc in
let name = CFrontend_config.this in
let pvar = Sil.mk_pvar (Mangled.from_string name) procname in
let exp = Sil.Lvar pvar in
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 class_type_ptr 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 } ~strip_pointer:false
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 expr_info.Clang_ast_t.ei_type_ptr
let rec labelStmt_trans trans_state stmt_info stmt_list label_name =
(* go ahead with the translation *)
let res_trans = match stmt_list with
@ -547,7 +548,7 @@ struct
Cfg.Node.set_succs_exn root_node' res_trans.root_nodes [];
{ empty_res_trans with root_nodes = [root_node']; leaf_nodes = trans_state.succ_nodes }
and decl_ref_trans trans_state pre_trans_result stmt_info expr_info decl_ref =
and decl_ref_trans trans_state pre_trans_result stmt_info decl_ref =
let open CContext in
Printing.log_out " priority node free = '%s'\n@."
(string_of_bool (PriorityNode.is_priority_free trans_state));
@ -574,7 +575,7 @@ struct
let decl_ref = match decl_ref_expr_info.Clang_ast_t.drti_decl_ref with
| Some dr -> dr
| None -> assert false in
decl_ref_trans trans_state empty_res_trans stmt_info expr_info decl_ref
decl_ref_trans trans_state empty_res_trans stmt_info decl_ref
(* evaluates an enum constant *)
and enum_const_eval context enum_constant_pointer prev_enum_constant_opt zero =
@ -879,7 +880,7 @@ struct
exps = [(var_exp, this_type)];
initd_exps = [var_exp];
} in
let res_trans_callee = decl_ref_trans trans_state this_res_trans si ei decl_ref in
let res_trans_callee = decl_ref_trans trans_state this_res_trans si decl_ref in
let res_trans = cxx_method_construct_call_trans trans_state_pri res_trans_callee
params_stmt si Sil.Tvoid in
{ res_trans with exps = [(var_exp, class_type)] }
@ -1710,7 +1711,7 @@ struct
(* int p = X(1).field; *)
let trans_state' = { trans_state with var_exp_typ = None } in
let result_trans_exp_stmt = exec_with_glvalue_as_reference instruction trans_state' exp_stmt in
decl_ref_trans trans_state result_trans_exp_stmt stmt_info expr_info decl_ref
decl_ref_trans trans_state result_trans_exp_stmt stmt_info decl_ref
and objCIvarRefExpr_trans trans_state stmt_info expr_info stmt_list obj_c_ivar_ref_expr_info =
let decl_ref = obj_c_ivar_ref_expr_info.Clang_ast_t.ovrei_decl_ref in
@ -2227,6 +2228,38 @@ struct
(Ast_utils.string_of_stmt s);
assert false)
(* Function similar to instruction function, but it takes C++ constructor initializer as *)
(* an input parameter. *)
and cxx_constructor_init_trans ctor_init trans_state =
(*let tenv = trans_state.context.CContext.tenv in*)
let class_name = CContext.get_curr_class_name trans_state.context.CContext.curr_class in
let sil_loc =
CLocation.get_sil_location_from_range ctor_init.Clang_ast_t.xci_source_range true in
(* its pointer will be used in PriorityNode *)
let this_stmt_info = Ast_expressions.dummy_stmt_info () in
(* this will be used to avoid creating node in init_expr_trans *)
let child_stmt_info = Ast_expressions.dummy_stmt_info () in
let trans_state' = PriorityNode.try_claim_priority_node trans_state this_stmt_info in
let class_type_ptr = Ast_expressions.create_pointer_type
(Ast_expressions.create_class_type (class_name, `CPP)) in
let this_res_trans = this_expr_trans trans_state' sil_loc class_type_ptr in
let var_res_trans = match ctor_init.Clang_ast_t.xci_subject with
| `Delegating _ | `BaseClass _ ->
let this_exp, this_typ = extract_exp_from_list this_res_trans.exps
"WARNING: There should be one expression for 'this' in constructor. \n" in
(* Hack: Strip pointer from type here since cxxConstructExpr_trans expects it this way *)
(* it will add pointer back before making it a parameter to a call *)
let class_typ = match this_typ with Sil.Tptr (t, _) -> t | _ -> assert false in
{ this_res_trans with exps = [this_exp, class_typ] }
| `Member (decl_ref) ->
decl_ref_trans trans_state' this_res_trans child_stmt_info decl_ref in
let var_exp_typ = extract_exp_from_list var_res_trans.exps
"WARNING: There should be one expression to initialize in constructor initializer. \n" in
let init_expr = ctor_init.Clang_ast_t.xci_init_expr in
let init_res_trans = init_expr_trans trans_state' var_exp_typ child_stmt_info init_expr in
PriorityNode.compute_results_to_parent trans_state' sil_loc "Constructor Init"
this_stmt_info [var_res_trans; init_res_trans]
(** Given a translation state and list of translation functions it executes translation *)
and exec_trans_instrs trans_state trans_stmt_fun_list =
let rec exec_trans_instrs_no_rev trans_state rev_trans_fun_list = match rev_trans_fun_list with
@ -2253,7 +2286,7 @@ struct
(* TODO write translate function for cxx constructor exprs *)
and get_custom_stmt_trans stmt = match stmt with
| `ClangStmt stmt -> get_clang_stmt_trans stmt
| `CXXConstructorInit instr -> empty_trans_fun
| `CXXConstructorInit instr -> cxx_constructor_init_trans instr
(** Given a translation state, this function translates a list of clang statements. *)
and instructions trans_state stmt_list =

@ -107,6 +107,7 @@ let is_block_type tp =
let is_reference_type tp =
match Ast_utils.get_desugared_type tp with
| Some Clang_ast_t.LValueReferenceType _ -> true
| Some Clang_ast_t.RValueReferenceType _ -> true
| _ -> false
(* Expand a named type Tvar if it has a definition in tenv. This is used for Tenum, Tstruct, etc. *)

@ -0,0 +1,69 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
struct A {
int f;
A(int f) : f(f) {
}
};
struct B : public A {
struct T {
int v;
T(int v) : v(v) {}
};
int f2;
T t;
B(int a) :
A(a),
f2(a),
t(a) {
}
B(int a, int b) :
B(a+b) {
f2 = b;
}
};
int f2_div0() {
B b(0);
return 1/b.f2;
}
int f_div0() {
B b(0);
return 1/b.f;
}
int t_div0() {
B b(0);
return 1/b.t.v;
}
int delegate_constr_f_div0() {
B b(-1, 1);
int v = 1/b.f2;
return 1/b.f;
}
int delegate_constr_f2_div0() {
B b(-1, 0);
int v = 1/b.f;
return 1/b.f2;
}
int f_f2_div1() {
B b(1);
int v = 1/b.f;
int v2 = 1/b.f2;
int v3 = 1/b.t.v;
return v + v2;
}

@ -0,0 +1,168 @@
digraph iCFG {
44 [label="44: DeclStmt \n _fun_B_B(&b:class B *,1:int ) [line 64]\n " shape="box"]
44 -> 43 ;
43 [label="43: DeclStmt \n n$4=*&b.f:int [line 65]\n *&v:int =(1 / n$4) [line 65]\n REMOVE_TEMPS(n$4); [line 65]\n " shape="box"]
43 -> 42 ;
42 [label="42: DeclStmt \n n$3=*&b.f2:int [line 66]\n *&v2:int =(1 / n$3) [line 66]\n REMOVE_TEMPS(n$3); [line 66]\n " shape="box"]
42 -> 41 ;
41 [label="41: DeclStmt \n n$2=*&b.t.v:int [line 67]\n *&v3:int =(1 / n$2) [line 67]\n REMOVE_TEMPS(n$2); [line 67]\n NULLIFY(&v3,false); [line 67]\n " shape="box"]
41 -> 40 ;
40 [label="40: Return Stmt \n n$0=*&v:int [line 68]\n n$1=*&v2:int [line 68]\n *&return:int =(n$0 + n$1) [line 68]\n REMOVE_TEMPS(n$0,n$1); [line 68]\n NULLIFY(&v,false); [line 68]\n NULLIFY(&v2,false); [line 68]\n NULLIFY(&b,false); [line 68]\n APPLY_ABSTRACTION; [line 68]\n " shape="box"]
40 -> 39 ;
39 [label="39: Exit f_f2_div1 \n " color=yellow style=filled]
38 [label="38: Start f_f2_div1\nFormals: \nLocals: v3:int v2:int v:int b:class B \n DECLARE_LOCALS(&return,&v3,&v2,&v,&b); [line 63]\n NULLIFY(&v,false); [line 63]\n NULLIFY(&v2,false); [line 63]\n NULLIFY(&v3,false); [line 63]\n " color=yellow style=filled]
38 -> 44 ;
37 [label="37: DeclStmt \n _fun_B_B(&b:class B *,-1:int ,0:int ) [line 58]\n " shape="box"]
37 -> 36 ;
36 [label="36: DeclStmt \n n$1=*&b.f:int [line 59]\n *&v:int =(1 / n$1) [line 59]\n REMOVE_TEMPS(n$1); [line 59]\n NULLIFY(&v,false); [line 59]\n " shape="box"]
36 -> 35 ;
35 [label="35: Return Stmt \n n$0=*&b.f2:int [line 60]\n *&return:int =(1 / n$0) [line 60]\n REMOVE_TEMPS(n$0); [line 60]\n NULLIFY(&b,false); [line 60]\n APPLY_ABSTRACTION; [line 60]\n " shape="box"]
35 -> 34 ;
34 [label="34: Exit delegate_constr_f2_div0 \n " color=yellow style=filled]
33 [label="33: Start delegate_constr_f2_div0\nFormals: \nLocals: v:int b:class B \n DECLARE_LOCALS(&return,&v,&b); [line 57]\n NULLIFY(&v,false); [line 57]\n " color=yellow style=filled]
33 -> 37 ;
32 [label="32: DeclStmt \n _fun_B_B(&b:class B *,-1:int ,1:int ) [line 52]\n " shape="box"]
32 -> 31 ;
31 [label="31: DeclStmt \n n$1=*&b.f2:int [line 53]\n *&v:int =(1 / n$1) [line 53]\n REMOVE_TEMPS(n$1); [line 53]\n NULLIFY(&v,false); [line 53]\n " shape="box"]
31 -> 30 ;
30 [label="30: Return Stmt \n n$0=*&b.f:int [line 54]\n *&return:int =(1 / n$0) [line 54]\n REMOVE_TEMPS(n$0); [line 54]\n NULLIFY(&b,false); [line 54]\n APPLY_ABSTRACTION; [line 54]\n " shape="box"]
30 -> 29 ;
29 [label="29: Exit delegate_constr_f_div0 \n " color=yellow style=filled]
28 [label="28: Start delegate_constr_f_div0\nFormals: \nLocals: v:int b:class B \n DECLARE_LOCALS(&return,&v,&b); [line 51]\n NULLIFY(&v,false); [line 51]\n " color=yellow style=filled]
28 -> 32 ;
27 [label="27: DeclStmt \n _fun_B_B(&b:class B *,0:int ) [line 47]\n " shape="box"]
27 -> 26 ;
26 [label="26: Return Stmt \n n$0=*&b.t.v:int [line 48]\n *&return:int =(1 / n$0) [line 48]\n REMOVE_TEMPS(n$0); [line 48]\n NULLIFY(&b,false); [line 48]\n APPLY_ABSTRACTION; [line 48]\n " shape="box"]
26 -> 25 ;
25 [label="25: Exit t_div0 \n " color=yellow style=filled]
24 [label="24: Start t_div0\nFormals: \nLocals: b:class B \n DECLARE_LOCALS(&return,&b); [line 46]\n " color=yellow style=filled]
24 -> 27 ;
23 [label="23: DeclStmt \n _fun_B_B(&b:class B *,0:int ) [line 42]\n " shape="box"]
23 -> 22 ;
22 [label="22: Return Stmt \n n$0=*&b.f:int [line 43]\n *&return:int =(1 / n$0) [line 43]\n REMOVE_TEMPS(n$0); [line 43]\n NULLIFY(&b,false); [line 43]\n APPLY_ABSTRACTION; [line 43]\n " shape="box"]
22 -> 21 ;
21 [label="21: Exit f_div0 \n " color=yellow style=filled]
20 [label="20: Start f_div0\nFormals: \nLocals: b:class B \n DECLARE_LOCALS(&return,&b); [line 41]\n " color=yellow style=filled]
20 -> 23 ;
19 [label="19: DeclStmt \n _fun_B_B(&b:class B *,0:int ) [line 37]\n " shape="box"]
19 -> 18 ;
18 [label="18: Return Stmt \n n$0=*&b.f2:int [line 38]\n *&return:int =(1 / n$0) [line 38]\n REMOVE_TEMPS(n$0); [line 38]\n NULLIFY(&b,false); [line 38]\n APPLY_ABSTRACTION; [line 38]\n " shape="box"]
18 -> 17 ;
17 [label="17: Exit f2_div0 \n " color=yellow style=filled]
16 [label="16: Start f2_div0\nFormals: \nLocals: b:class B \n DECLARE_LOCALS(&return,&b); [line 36]\n " color=yellow style=filled]
16 -> 19 ;
15 [label="15: Constructor Init \n n$2=*&this:class B * [line 30]\n n$3=*&a:int [line 30]\n n$4=*&b:int [line 30]\n _fun_B_B(n$2:class B *,(n$3 + n$4):int ) [line 30]\n REMOVE_TEMPS(n$2,n$3,n$4); [line 30]\n NULLIFY(&a,false); [line 30]\n " shape="box"]
15 -> 14 ;
14 [label="14: BinaryOperatorStmt: Assign \n n$0=*&this:class B * [line 31]\n n$1=*&b:int [line 31]\n *n$0.f2:int =n$1 [line 31]\n REMOVE_TEMPS(n$0,n$1); [line 31]\n NULLIFY(&b,false); [line 31]\n NULLIFY(&this,false); [line 31]\n APPLY_ABSTRACTION; [line 31]\n " shape="box"]
14 -> 13 ;
13 [label="13: Exit B_B \n " color=yellow style=filled]
12 [label="12: Start B_B\nFormals: this:class B * a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [line 29]\n " color=yellow style=filled]
12 -> 15 ;
11 [label="11: Constructor Init \n n$4=*&this:class B * [line 24]\n n$5=*&a:int [line 24]\n _fun_A_A(n$4:class B *,n$5:int ) [line 24]\n REMOVE_TEMPS(n$4,n$5); [line 24]\n " shape="box"]
11 -> 10 ;
10 [label="10: Constructor Init \n n$2=*&this:class B * [line 25]\n n$3=*&a:int [line 25]\n *n$2.f2:int =n$3 [line 25]\n REMOVE_TEMPS(n$2,n$3); [line 25]\n " shape="box"]
10 -> 9 ;
9 [label="9: Constructor Init \n n$0=*&this:class B * [line 26]\n n$1=*&a:int [line 26]\n _fun_B::T_T(n$0.t:class B::T *,n$1:int ) [line 26]\n REMOVE_TEMPS(n$0,n$1); [line 26]\n NULLIFY(&a,false); [line 26]\n NULLIFY(&this,false); [line 26]\n APPLY_ABSTRACTION; [line 26]\n " shape="box"]
9 -> 8 ;
8 [label="8: Exit B_B \n " color=yellow style=filled]
7 [label="7: Start B_B\nFormals: this:class B * a:int \nLocals: \n DECLARE_LOCALS(&return); [line 23]\n " color=yellow style=filled]
7 -> 11 ;
6 [label="6: Constructor Init \n n$0=*&this:class B::T * [line 19]\n n$1=*&v:int [line 19]\n *n$0.v:int =n$1 [line 19]\n REMOVE_TEMPS(n$0,n$1); [line 19]\n NULLIFY(&this,false); [line 19]\n NULLIFY(&v,false); [line 19]\n APPLY_ABSTRACTION; [line 19]\n " shape="box"]
6 -> 5 ;
5 [label="5: Exit B::T_T \n " color=yellow style=filled]
4 [label="4: Start B::T_T\nFormals: this:class B::T * v:int \nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
4 -> 6 ;
3 [label="3: Constructor Init \n n$0=*&this:class A * [line 12]\n n$1=*&f:int [line 12]\n *n$0.f:int =n$1 [line 12]\n REMOVE_TEMPS(n$0,n$1); [line 12]\n NULLIFY(&f,false); [line 12]\n NULLIFY(&this,false); [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"]
3 -> 2 ;
2 [label="2: Exit A_A \n " color=yellow style=filled]
1 [label="1: Start A_A\nFormals: this:class A * f:int \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled]
1 -> 3 ;
}

@ -0,0 +1,84 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: that test will break if we start doing copy elision
// will have default copy/move constructors - used to test
// whether they get translated correctly
struct X {
int f;
};
// used to test whether backend can distinguish copy
// and move constructor
struct Y {
int f;
Y() = default;
Y(const Y &y) = default;
// move constructor with different behavior than copy constructor
Y(const Y &&y) : f(y.f - 1) {}
};
X getX(int f) {
X x;
x.f = f;
return x; // will call move constructor
}
Y getY(int f) {
Y y;
y.f = f;
return y;
}
int copyX_div0() {
X x1;
x1.f = 0;
X x2 = x1; // will call copy constructor
return 1 / x2.f;
}
int moveX_div0() {
return 1 / getX(0).f;
}
int copyY_div0() {
Y y1;
y1.f = 0;
Y y2 = y1; // will call copy constructor
return 1 / y2.f;
}
int moveY_div0() {
return 1 / getY(1).f;
}
int moveY_moveY_copyY_div0() {
Y y1 = getY(2); //move constructor in getY and in assignment
Y y2 = y1;
return 1 / y2.f;
}
int copyX_moveX_div1() {
X x1;
x1.f = 1;
X x2 = x1;
int d1 = 1 / x2.f;
int d2 = 1 / getX(1).f;
return d1 + d2;
}
int copyY_moveY_div1() {
Y y1;
y1.f = 1;
Y y2 = y1;
int d1 = 1 / y2.f;
int d2 = 1 / getY(2).f;
return d1 + d2;
}

@ -0,0 +1,247 @@
digraph iCFG {
65 [label="65: DeclStmt \n _fun_Y_Y(&y1:class Y *) [line 78]\n " shape="box"]
65 -> 64 ;
64 [label="64: BinaryOperatorStmt: Assign \n *&y1.f:int =1 [line 79]\n " shape="box"]
64 -> 63 ;
63 [label="63: DeclStmt \n _fun_Y_Y(&y2:class Y *,&y1:class Y &) [line 80]\n " shape="box"]
63 -> 62 ;
62 [label="62: DeclStmt \n n$5=*&y2.f:int [line 81]\n *&d1:int =(1 / n$5) [line 81]\n REMOVE_TEMPS(n$5); [line 81]\n " shape="box"]
62 -> 61 ;
61 [label="61: DeclStmt \n _fun_getY(2:int ,&__temp_return_n$3:class Y *) [line 82]\n n$4=*&__temp_return_n$3.f:int [line 82]\n *&d2:int =(1 / n$4) [line 82]\n REMOVE_TEMPS(n$4); [line 82]\n " shape="box"]
61 -> 60 ;
60 [label="60: Return Stmt \n n$0=*&d1:int [line 83]\n n$1=*&d2:int [line 83]\n *&return:int =(n$0 + n$1) [line 83]\n REMOVE_TEMPS(n$0,n$1); [line 83]\n NULLIFY(&d1,false); [line 83]\n NULLIFY(&d2,false); [line 83]\n NULLIFY(&__temp_return_n$3,false); [line 83]\n NULLIFY(&y1,false); [line 83]\n NULLIFY(&y2,false); [line 83]\n APPLY_ABSTRACTION; [line 83]\n " shape="box"]
60 -> 59 ;
59 [label="59: Exit copyY_moveY_div1 \n " color=yellow style=filled]
58 [label="58: Start copyY_moveY_div1\nFormals: \nLocals: d2:int __temp_return_n$3:class Y d1:int y2:class Y y1:class Y \n DECLARE_LOCALS(&return,&d2,&__temp_return_n$3,&d1,&y2,&y1); [line 77]\n NULLIFY(&d1,false); [line 77]\n NULLIFY(&d2,false); [line 77]\n " color=yellow style=filled]
58 -> 65 ;
57 [label="57: DeclStmt \n _fun_X_X(&x1:class X *) [line 69]\n " shape="box"]
57 -> 56 ;
56 [label="56: BinaryOperatorStmt: Assign \n *&x1.f:int =1 [line 70]\n " shape="box"]
56 -> 55 ;
55 [label="55: DeclStmt \n _fun_X_X(&x2:class X *,&x1:class X &) [line 71]\n " shape="box"]
55 -> 54 ;
54 [label="54: DeclStmt \n n$5=*&x2.f:int [line 72]\n *&d1:int =(1 / n$5) [line 72]\n REMOVE_TEMPS(n$5); [line 72]\n " shape="box"]
54 -> 53 ;
53 [label="53: DeclStmt \n _fun_getX(1:int ,&__temp_return_n$3:class X *) [line 73]\n n$4=*&__temp_return_n$3.f:int [line 73]\n *&d2:int =(1 / n$4) [line 73]\n REMOVE_TEMPS(n$4); [line 73]\n " shape="box"]
53 -> 52 ;
52 [label="52: Return Stmt \n n$0=*&d1:int [line 74]\n n$1=*&d2:int [line 74]\n *&return:int =(n$0 + n$1) [line 74]\n REMOVE_TEMPS(n$0,n$1); [line 74]\n NULLIFY(&d1,false); [line 74]\n NULLIFY(&d2,false); [line 74]\n NULLIFY(&__temp_return_n$3,false); [line 74]\n NULLIFY(&x1,false); [line 74]\n NULLIFY(&x2,false); [line 74]\n APPLY_ABSTRACTION; [line 74]\n " shape="box"]
52 -> 51 ;
51 [label="51: Exit copyX_moveX_div1 \n " color=yellow style=filled]
50 [label="50: Start copyX_moveX_div1\nFormals: \nLocals: d2:int __temp_return_n$3:class X d1:int x2:class X x1:class X \n DECLARE_LOCALS(&return,&d2,&__temp_return_n$3,&d1,&x2,&x1); [line 68]\n NULLIFY(&d1,false); [line 68]\n NULLIFY(&d2,false); [line 68]\n " color=yellow style=filled]
50 -> 57 ;
49 [label="49: DeclStmt \n _fun_getY(2:int ,&SIL_materialize_temp__n$1:class Y *) [line 63]\n _fun_Y_Y(&y1:class Y *,&SIL_materialize_temp__n$1:class Y &) [line 63]\n " shape="box"]
49 -> 48 ;
48 [label="48: DeclStmt \n _fun_Y_Y(&y2:class Y *,&y1:class Y &) [line 64]\n " shape="box"]
48 -> 47 ;
47 [label="47: Return Stmt \n n$0=*&y2.f:int [line 65]\n *&return:int =(1 / n$0) [line 65]\n REMOVE_TEMPS(n$0); [line 65]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 65]\n NULLIFY(&y1,false); [line 65]\n NULLIFY(&y2,false); [line 65]\n APPLY_ABSTRACTION; [line 65]\n " shape="box"]
47 -> 46 ;
46 [label="46: Exit moveY_moveY_copyY_div0 \n " color=yellow style=filled]
45 [label="45: Start moveY_moveY_copyY_div0\nFormals: \nLocals: y2:class Y y1:class Y SIL_materialize_temp__n$1:class Y \n DECLARE_LOCALS(&return,&y2,&y1,&SIL_materialize_temp__n$1); [line 62]\n " color=yellow style=filled]
45 -> 49 ;
44 [label="44: Return Stmt \n _fun_getY(1:int ,&__temp_return_n$1:class Y *) [line 59]\n n$2=*&__temp_return_n$1.f:int [line 59]\n *&return:int =(1 / n$2) [line 59]\n REMOVE_TEMPS(n$2); [line 59]\n NULLIFY(&__temp_return_n$1,false); [line 59]\n APPLY_ABSTRACTION; [line 59]\n " shape="box"]
44 -> 43 ;
43 [label="43: Exit moveY_div0 \n " color=yellow style=filled]
42 [label="42: Start moveY_div0\nFormals: \nLocals: __temp_return_n$1:class Y \n DECLARE_LOCALS(&return,&__temp_return_n$1); [line 58]\n " color=yellow style=filled]
42 -> 44 ;
41 [label="41: DeclStmt \n _fun_Y_Y(&y1:class Y *) [line 52]\n " shape="box"]
41 -> 40 ;
40 [label="40: BinaryOperatorStmt: Assign \n *&y1.f:int =0 [line 53]\n " shape="box"]
40 -> 39 ;
39 [label="39: DeclStmt \n _fun_Y_Y(&y2:class Y *,&y1:class Y &) [line 54]\n " shape="box"]
39 -> 38 ;
38 [label="38: Return Stmt \n n$0=*&y2.f:int [line 55]\n *&return:int =(1 / n$0) [line 55]\n REMOVE_TEMPS(n$0); [line 55]\n NULLIFY(&y1,false); [line 55]\n NULLIFY(&y2,false); [line 55]\n APPLY_ABSTRACTION; [line 55]\n " shape="box"]
38 -> 37 ;
37 [label="37: Exit copyY_div0 \n " color=yellow style=filled]
36 [label="36: Start copyY_div0\nFormals: \nLocals: y2:class Y y1:class Y \n DECLARE_LOCALS(&return,&y2,&y1); [line 51]\n " color=yellow style=filled]
36 -> 41 ;
35 [label="35: Return Stmt \n _fun_getX(0:int ,&__temp_return_n$1:class X *) [line 47]\n n$2=*&__temp_return_n$1.f:int [line 47]\n *&return:int =(1 / n$2) [line 47]\n REMOVE_TEMPS(n$2); [line 47]\n NULLIFY(&__temp_return_n$1,false); [line 47]\n APPLY_ABSTRACTION; [line 47]\n " shape="box"]
35 -> 34 ;
34 [label="34: Exit moveX_div0 \n " color=yellow style=filled]
33 [label="33: Start moveX_div0\nFormals: \nLocals: __temp_return_n$1:class X \n DECLARE_LOCALS(&return,&__temp_return_n$1); [line 46]\n " color=yellow style=filled]
33 -> 35 ;
32 [label="32: DeclStmt \n _fun_X_X(&x1:class X *) [line 40]\n " shape="box"]
32 -> 31 ;
31 [label="31: BinaryOperatorStmt: Assign \n *&x1.f:int =0 [line 41]\n " shape="box"]
31 -> 30 ;
30 [label="30: DeclStmt \n _fun_X_X(&x2:class X *,&x1:class X &) [line 42]\n " shape="box"]
30 -> 29 ;
29 [label="29: Return Stmt \n n$0=*&x2.f:int [line 43]\n *&return:int =(1 / n$0) [line 43]\n REMOVE_TEMPS(n$0); [line 43]\n NULLIFY(&x1,false); [line 43]\n NULLIFY(&x2,false); [line 43]\n APPLY_ABSTRACTION; [line 43]\n " shape="box"]
29 -> 28 ;
28 [label="28: Exit copyX_div0 \n " color=yellow style=filled]
27 [label="27: Start copyX_div0\nFormals: \nLocals: x2:class X x1:class X \n DECLARE_LOCALS(&return,&x2,&x1); [line 39]\n " color=yellow style=filled]
27 -> 32 ;
26 [label="26: DeclStmt \n _fun_Y_Y(&y:class Y *) [line 34]\n " shape="box"]
26 -> 25 ;
25 [label="25: BinaryOperatorStmt: Assign \n n$1=*&f:int [line 35]\n *&y.f:int =n$1 [line 35]\n REMOVE_TEMPS(n$1); [line 35]\n NULLIFY(&f,false); [line 35]\n " shape="box"]
25 -> 24 ;
24 [label="24: Return Stmt \n n$0=*&__return_param:class Y * [line 36]\n _fun_Y_Y(n$0:class Y *,&y:class Y &) [line 36]\n REMOVE_TEMPS(n$0); [line 36]\n NULLIFY(&__return_param,false); [line 36]\n NULLIFY(&y,false); [line 36]\n APPLY_ABSTRACTION; [line 36]\n " shape="box"]
24 -> 23 ;
23 [label="23: Exit getY \n " color=yellow style=filled]
22 [label="22: Start getY\nFormals: f:int __return_param:class Y *\nLocals: y:class Y \n DECLARE_LOCALS(&return,&y); [line 33]\n " color=yellow style=filled]
22 -> 26 ;
21 [label="21: DeclStmt \n _fun_X_X(&x:class X *) [line 28]\n " shape="box"]
21 -> 20 ;
20 [label="20: BinaryOperatorStmt: Assign \n n$1=*&f:int [line 29]\n *&x.f:int =n$1 [line 29]\n REMOVE_TEMPS(n$1); [line 29]\n NULLIFY(&f,false); [line 29]\n " shape="box"]
20 -> 19 ;
19 [label="19: Return Stmt \n n$0=*&__return_param:class X * [line 30]\n _fun_X_X(n$0:class X *,&x:class X &) [line 30]\n REMOVE_TEMPS(n$0); [line 30]\n NULLIFY(&__return_param,false); [line 30]\n NULLIFY(&x,false); [line 30]\n APPLY_ABSTRACTION; [line 30]\n " shape="box"]
19 -> 18 ;
18 [label="18: Exit getX \n " color=yellow style=filled]
17 [label="17: Start getX\nFormals: f:int __return_param:class X *\nLocals: x:class X \n DECLARE_LOCALS(&return,&x); [line 27]\n " color=yellow style=filled]
17 -> 21 ;
16 [label="16: Constructor Init \n n$0=*&this:class Y * [line 24]\n n$1=*&y:class Y & [line 24]\n n$2=*n$1.f:int [line 24]\n *n$0.f:int =(n$2 - 1) [line 24]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 24]\n NULLIFY(&this,false); [line 24]\n NULLIFY(&y,false); [line 24]\n APPLY_ABSTRACTION; [line 24]\n " shape="box"]
16 -> 15 ;
15 [label="15: Exit Y_Y \n " color=yellow style=filled]
14 [label="14: Start Y_Y\nFormals: this:class Y * y:class Y &\nLocals: \n DECLARE_LOCALS(&return); [line 24]\n " color=yellow style=filled]
14 -> 16 ;
13 [label="13: Constructor Init \n n$0=*&this:class Y * [line 22]\n n$1=*&y:class Y & [line 22]\n n$2=*n$1.f:int [line 22]\n *n$0.f:int =n$2 [line 22]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 22]\n NULLIFY(&this,false); [line 22]\n NULLIFY(&y,false); [line 22]\n APPLY_ABSTRACTION; [line 22]\n " shape="box"]
13 -> 12 ;
12 [label="12: Exit Y_Y \n " color=yellow style=filled]
11 [label="11: Start Y_Y\nFormals: this:class Y * y:class Y &\nLocals: \n DECLARE_LOCALS(&return); [line 22]\n " color=yellow style=filled]
11 -> 13 ;
10 [label="10: Exit Y_Y \n " color=yellow style=filled]
9 [label="9: Start Y_Y\nFormals: this:class Y *\nLocals: \n DECLARE_LOCALS(&return); [line 21]\n NULLIFY(&this,false); [line 21]\n " color=yellow style=filled]
9 -> 10 ;
8 [label="8: Constructor Init \n n$0=*&this:class X * [line 13]\n n$1=*&__param_0:class X & [line 13]\n n$2=*n$1.f:int [line 13]\n *n$0.f:int =n$2 [line 13]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 13]\n NULLIFY(&__param_0,false); [line 13]\n NULLIFY(&this,false); [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"]
8 -> 7 ;
7 [label="7: Exit X_X \n " color=yellow style=filled]
6 [label="6: Start X_X\nFormals: this:class X * __param_0:class X &\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
6 -> 8 ;
5 [label="5: Constructor Init \n n$0=*&this:class X * [line 13]\n n$1=*&__param_0:class X & [line 13]\n n$2=*n$1.f:int [line 13]\n *n$0.f:int =n$2 [line 13]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 13]\n NULLIFY(&__param_0,false); [line 13]\n NULLIFY(&this,false); [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"]
5 -> 4 ;
4 [label="4: Exit X_X \n " color=yellow style=filled]
3 [label="3: Start X_X\nFormals: this:class X * __param_0:class X &\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
3 -> 5 ;
2 [label="2: Exit X_X \n " color=yellow style=filled]
1 [label="1: Start X_X\nFormals: this:class X *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n NULLIFY(&this,false); [line 13]\n " color=yellow style=filled]
1 -> 2 ;
}

@ -1,41 +1,45 @@
digraph iCFG {
12 [label="12: DeclStmt \n n$2=*&a:class A * [line 22]\n _fun_A_get(n$2:class A *,1:int ,&SIL_materialize_temp__n$1:class X *) [line 22]\n _fun_X_X(&x:class X *,&SIL_materialize_temp__n$1:class X &) [line 22]\n REMOVE_TEMPS(n$2); [line 22]\n NULLIFY(&a,false); [line 22]\n " shape="box"]
13 [label="13: DeclStmt \n n$2=*&a:class A * [line 22]\n _fun_A_get(n$2:class A *,1:int ,&SIL_materialize_temp__n$1:class X *) [line 22]\n _fun_X_X(&x:class X *,&SIL_materialize_temp__n$1:class X &) [line 22]\n REMOVE_TEMPS(n$2); [line 22]\n NULLIFY(&a,false); [line 22]\n " shape="box"]
13 -> 12 ;
12 [label="12: Return Stmt \n n$0=*&x.f:int [line 23]\n *&return:int =(1 / n$0) [line 23]\n REMOVE_TEMPS(n$0); [line 23]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 23]\n NULLIFY(&x,false); [line 23]\n APPLY_ABSTRACTION; [line 23]\n " shape="box"]
12 -> 11 ;
11 [label="11: Return Stmt \n n$0=*&x.f:int [line 23]\n *&return:int =(1 / n$0) [line 23]\n REMOVE_TEMPS(n$0); [line 23]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 23]\n NULLIFY(&x,false); [line 23]\n APPLY_ABSTRACTION; [line 23]\n " shape="box"]
11 [label="11: Exit test \n " color=yellow style=filled]
11 -> 10 ;
10 [label="10: Exit test \n " color=yellow style=filled]
10 [label="10: Start test\nFormals: a:class A *\nLocals: x:class X SIL_materialize_temp__n$1:class X \n DECLARE_LOCALS(&return,&x,&SIL_materialize_temp__n$1); [line 21]\n " color=yellow style=filled]
9 [label="9: Start test\nFormals: a:class A *\nLocals: x:class X SIL_materialize_temp__n$1:class X \n DECLARE_LOCALS(&return,&x,&SIL_materialize_temp__n$1); [line 21]\n " color=yellow style=filled]
10 -> 13 ;
9 [label="9: DeclStmt \n _fun_X_X(&x:class X *) [line 16]\n " shape="box"]
9 -> 12 ;
8 [label="8: DeclStmt \n _fun_X_X(&x:class X *) [line 16]\n " shape="box"]
9 -> 8 ;
8 [label="8: Return Stmt \n n$0=*&__return_param:class X * [line 17]\n _fun_X_X(n$0:class X *,&x:class X &) [line 17]\n REMOVE_TEMPS(n$0); [line 17]\n NULLIFY(&__return_param,false); [line 17]\n NULLIFY(&x,false); [line 17]\n APPLY_ABSTRACTION; [line 17]\n " shape="box"]
8 -> 7 ;
7 [label="7: Return Stmt \n n$0=*&__return_param:class X * [line 17]\n _fun_X_X(n$0:class X *,&x:class X &) [line 17]\n REMOVE_TEMPS(n$0); [line 17]\n NULLIFY(&__return_param,false); [line 17]\n NULLIFY(&x,false); [line 17]\n APPLY_ABSTRACTION; [line 17]\n " shape="box"]
7 [label="7: Exit A_get \n " color=yellow style=filled]
7 -> 6 ;
6 [label="6: Exit A_get \n " color=yellow style=filled]
6 [label="6: Start A_get\nFormals: this:class A * p:int __return_param:class X *\nLocals: x:class X \n DECLARE_LOCALS(&return,&x); [line 15]\n NULLIFY(&p,false); [line 15]\n NULLIFY(&this,false); [line 15]\n " color=yellow style=filled]
5 [label="5: Start A_get\nFormals: this:class A * p:int __return_param:class X *\nLocals: x:class X \n DECLARE_LOCALS(&return,&x); [line 15]\n NULLIFY(&p,false); [line 15]\n NULLIFY(&this,false); [line 15]\n " color=yellow style=filled]
6 -> 9 ;
5 [label="5: Constructor Init \n n$0=*&this:class X * [line 10]\n n$1=*&__param_0:class X & [line 10]\n n$2=*n$1.f:int [line 10]\n *n$0.f:int =n$2 [line 10]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 10]\n NULLIFY(&__param_0,false); [line 10]\n NULLIFY(&this,false); [line 10]\n APPLY_ABSTRACTION; [line 10]\n " shape="box"]
5 -> 8 ;
5 -> 4 ;
4 [label="4: Exit X_X \n " color=yellow style=filled]
3 [label="3: Start X_X\nFormals: this:class X * __param_0:class X &\nLocals: \n DECLARE_LOCALS(&return); [line 10]\n NULLIFY(&__param_0,false); [line 10]\n NULLIFY(&this,false); [line 10]\n " color=yellow style=filled]
3 [label="3: Start X_X\nFormals: this:class X * __param_0:class X &\nLocals: \n DECLARE_LOCALS(&return); [line 10]\n " color=yellow style=filled]
3 -> 4 ;
3 -> 5 ;
2 [label="2: Exit X_X \n " color=yellow style=filled]

@ -1,54 +1,58 @@
digraph iCFG {
24 [label="24: DeclStmt \n n$14=_fun___new(sizeof(class Base ):unsigned long ) [line 22]\n *&b:class Base *=n$14 [line 22]\n REMOVE_TEMPS(n$14); [line 22]\n " shape="box"]
25 [label="25: DeclStmt \n n$14=_fun___new(sizeof(class Base ):unsigned long ) [line 22]\n *&b:class Base *=n$14 [line 22]\n REMOVE_TEMPS(n$14); [line 22]\n " shape="box"]
25 -> 24 ;
24 [label="24: DeclStmt \n n$13=_fun___new(sizeof(class Sub ):unsigned long ) [line 23]\n *&s1:class Sub *=n$13 [line 23]\n REMOVE_TEMPS(n$13); [line 23]\n " shape="box"]
24 -> 23 ;
23 [label="23: DeclStmt \n n$13=_fun___new(sizeof(class Sub ):unsigned long ) [line 23]\n *&s1:class Sub *=n$13 [line 23]\n REMOVE_TEMPS(n$13); [line 23]\n " shape="box"]
23 [label="23: DeclStmt \n n$12=_fun___new(sizeof(class Sub ):unsigned long ) [line 24]\n *&s2:class Sub *=n$12 [line 24]\n REMOVE_TEMPS(n$12); [line 24]\n " shape="box"]
23 -> 22 ;
22 [label="22: DeclStmt \n n$12=_fun___new(sizeof(class Sub ):unsigned long ) [line 24]\n *&s2:class Sub *=n$12 [line 24]\n REMOVE_TEMPS(n$12); [line 24]\n " shape="box"]
22 [label="22: Call _fun_Base_fun \n n$10=*&b:class Base * [line 26]\n n$11=_fun_Base_fun(n$10:class Base *) [line 26]\n REMOVE_TEMPS(n$10,n$11); [line 26]\n " shape="box"]
22 -> 21 ;
21 [label="21: Call _fun_Base_fun \n n$10=*&b:class Base * [line 26]\n n$11=_fun_Base_fun(n$10:class Base *) [line 26]\n REMOVE_TEMPS(n$10,n$11); [line 26]\n " shape="box"]
21 [label="21: Call _fun_Base_fun \n n$8=*&s1:class Base * [line 27]\n n$9=_fun_Base_fun(n$8:class Base *) [line 27]\n REMOVE_TEMPS(n$8,n$9); [line 27]\n " shape="box"]
21 -> 20 ;
20 [label="20: Call _fun_Base_fun \n n$8=*&s1:class Base * [line 27]\n n$9=_fun_Base_fun(n$8:class Base *) [line 27]\n REMOVE_TEMPS(n$8,n$9); [line 27]\n " shape="box"]
20 [label="20: Call _fun_Base_fun \n n$6=*&s2:class Sub * [line 28]\n n$7=_fun_Base_fun(n$6:class Sub *) [line 28]\n REMOVE_TEMPS(n$6,n$7); [line 28]\n " shape="box"]
20 -> 19 ;
19 [label="19: Call _fun_Base_fun \n n$6=*&s2:class Sub * [line 28]\n n$7=_fun_Base_fun(n$6:class Sub *) [line 28]\n REMOVE_TEMPS(n$6,n$7); [line 28]\n " shape="box"]
19 [label="19: Call _fun_Base_fun_redefine \n n$4=*&b:class Base * [line 30]\n n$5=_fun_Base_fun_redefine(n$4:class Base *) [line 30]\n REMOVE_TEMPS(n$4,n$5); [line 30]\n NULLIFY(&b,false); [line 30]\n " shape="box"]
19 -> 18 ;
18 [label="18: Call _fun_Base_fun_redefine \n n$4=*&b:class Base * [line 30]\n n$5=_fun_Base_fun_redefine(n$4:class Base *) [line 30]\n REMOVE_TEMPS(n$4,n$5); [line 30]\n NULLIFY(&b,false); [line 30]\n " shape="box"]
18 [label="18: Call _fun_Base_fun_redefine \n n$2=*&s1:class Base * [line 31]\n n$3=_fun_Base_fun_redefine(n$2:class Base *) [line 31]\n REMOVE_TEMPS(n$2,n$3); [line 31]\n NULLIFY(&s1,false); [line 31]\n " shape="box"]
18 -> 17 ;
17 [label="17: Call _fun_Base_fun_redefine \n n$2=*&s1:class Base * [line 31]\n n$3=_fun_Base_fun_redefine(n$2:class Base *) [line 31]\n REMOVE_TEMPS(n$2,n$3); [line 31]\n NULLIFY(&s1,false); [line 31]\n " shape="box"]
17 [label="17: Call _fun_Sub_fun_redefine \n n$0=*&s2:class Sub * [line 32]\n n$1=_fun_Sub_fun_redefine(n$0:class Sub *) [line 32]\n REMOVE_TEMPS(n$0,n$1); [line 32]\n NULLIFY(&s2,false); [line 32]\n APPLY_ABSTRACTION; [line 32]\n " shape="box"]
17 -> 16 ;
16 [label="16: Call _fun_Sub_fun_redefine \n n$0=*&s2:class Sub * [line 32]\n n$1=_fun_Sub_fun_redefine(n$0:class Sub *) [line 32]\n REMOVE_TEMPS(n$0,n$1); [line 32]\n NULLIFY(&s2,false); [line 32]\n APPLY_ABSTRACTION; [line 32]\n " shape="box"]
16 [label="16: Exit call_static_methods \n " color=yellow style=filled]
16 -> 15 ;
15 [label="15: Exit call_static_methods \n " color=yellow style=filled]
15 [label="15: Start call_static_methods\nFormals: \nLocals: s2:class Sub * s1:class Base * b:class Base * \n DECLARE_LOCALS(&return,&s2,&s1,&b); [line 21]\n NULLIFY(&b,false); [line 21]\n NULLIFY(&s1,false); [line 21]\n NULLIFY(&s2,false); [line 21]\n " color=yellow style=filled]
14 [label="14: Start call_static_methods\nFormals: \nLocals: s2:class Sub * s1:class Base * b:class Base * \n DECLARE_LOCALS(&return,&s2,&s1,&b); [line 21]\n NULLIFY(&b,false); [line 21]\n NULLIFY(&s1,false); [line 21]\n NULLIFY(&s2,false); [line 21]\n " color=yellow style=filled]
15 -> 25 ;
14 [label="14: Constructor Init \n n$0=*&this:class Sub * [line 16]\n _fun_Base_Base(n$0:class Sub *) [line 16]\n REMOVE_TEMPS(n$0); [line 16]\n NULLIFY(&this,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"]
14 -> 24 ;
14 -> 13 ;
13 [label="13: Exit Sub_Sub \n " color=yellow style=filled]
12 [label="12: Start Sub_Sub\nFormals: this:class Sub *\nLocals: \n DECLARE_LOCALS(&return); [line 16]\n NULLIFY(&this,false); [line 16]\n " color=yellow style=filled]
12 [label="12: Start Sub_Sub\nFormals: this:class Sub *\nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled]
12 -> 13 ;
12 -> 14 ;
11 [label="11: Return Stmt \n *&return:int =20 [line 18]\n APPLY_ABSTRACTION; [line 18]\n " shape="box"]

@ -0,0 +1,67 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package endtoend.cpp;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class ConstructorInitTest {
public static final String FILE =
"infer/tests/codetoanalyze/cpp/frontend/constructors/constructor_init.cpp";
private static ImmutableList<String> inferCmd;
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
}
@Test
public void whenInferRunsOnDiv0MethodsErrorIsFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
String[] procedures = {
"f2_div0",
"f_div0",
"t_div0",
"delegate_constr_f_div0",
"delegate_constr_f2_div0",
};
assertThat(
"Results should contain the expected divide by zero",
inferResults,
containsExactly(
DIVIDE_BY_ZERO,
FILE,
procedures
)
);
}
}

@ -0,0 +1,67 @@
/*
* Copyright (c) 2016 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package endtoend.cpp;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsExactly.containsExactly;
import com.google.common.collect.ImmutableList;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.InferResults;
import utils.InferRunner;
public class CopyMoveConstructorTest {
public static final String FILE =
"infer/tests/codetoanalyze/cpp/frontend/constructors/copy_move_constructor.cpp";
private static ImmutableList<String> inferCmd;
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
}
@Test
public void whenInferRunsOnDiv0MethodsErrorIsFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
String[] procedures = {
"copyX_div0",
"moveX_div0",
"copyY_div0",
"moveY_div0",
"moveY_moveY_copyY_div0",
};
assertThat(
"Results should contain the expected divide by zero",
inferResults,
containsExactly(
DIVIDE_BY_ZERO,
FILE,
procedures
)
);
}
}

@ -46,4 +46,16 @@ public class ConstructorsTest {
throws InterruptedException, IOException, InferException {
frontendTest("temp_object.cpp");
}
@Test
public void testConstructorInitDotFilesMatch()
throws InterruptedException, IOException, InferException {
frontendTest("constructor_init.cpp");
}
@Test
public void testCopyMoveConstructorDotFilesMatch()
throws InterruptedException, IOException, InferException {
frontendTest("copy_move_constructor.cpp");
}
}

Loading…
Cancel
Save