Translate conversion operators

Reviewed By: dulmarod

Differential Revision: D2879813

fb-gh-sync-id: 52d2191
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-5
parent be86e5d15d
commit 9d7ab4b9c2

@ -78,6 +78,7 @@ let rec translate_one_declaration tenv cg cfg parent_dec dec =
| CXXMethodDecl (decl_info, name_info, type_ptr, function_decl_info, _) | CXXMethodDecl (decl_info, name_info, type_ptr, function_decl_info, _)
| CXXConstructorDecl (decl_info, name_info, type_ptr, function_decl_info, _) | CXXConstructorDecl (decl_info, name_info, type_ptr, function_decl_info, _)
| CXXConversionDecl (decl_info, name_info, type_ptr, function_decl_info, _)
| CXXDestructorDecl (decl_info, name_info, type_ptr, function_decl_info, _) -> | CXXDestructorDecl (decl_info, name_info, type_ptr, function_decl_info, _) ->
(* di_parent_pointer has pointer to lexical context such as class.*) (* di_parent_pointer has pointer to lexical context such as class.*)
(* If it's not defined, then it's the same as parent in AST *) (* If it's not defined, then it's the same as parent in AST *)
@ -100,7 +101,8 @@ let rec translate_one_declaration tenv cg cfg parent_dec dec =
| CXXRecordDecl (decl_info, _, _, _, decl_list, _, _, _) | CXXRecordDecl (decl_info, _, _, _, decl_list, _, _, _)
| RecordDecl (decl_info, _, _, _, decl_list, _, _) when not decl_info.di_is_implicit -> | RecordDecl (decl_info, _, _, _, decl_list, _, _) when not decl_info.di_is_implicit ->
let is_method_decl decl = match decl with let is_method_decl decl = match decl with
| CXXMethodDecl _ | CXXConstructorDecl _ | CXXDestructorDecl _ | FunctionTemplateDecl _ -> | CXXMethodDecl _ | CXXConstructorDecl _ | CXXConversionDecl _
| CXXDestructorDecl _ | FunctionTemplateDecl _ ->
true true
| _ -> false in | _ -> false in
let method_decls, no_method_decls = IList.partition is_method_decl decl_list in let method_decls, no_method_decls = IList.partition is_method_decl decl_list in

@ -98,7 +98,7 @@ struct
let process_one_method_decl tenv cg cfg curr_class dec = let process_one_method_decl tenv cg cfg curr_class dec =
let open Clang_ast_t in let open Clang_ast_t in
match dec with match dec with
| CXXMethodDecl _ | CXXConstructorDecl _ | CXXDestructorDecl _ -> | CXXMethodDecl _ | CXXConstructorDecl _ | CXXConversionDecl _ | CXXDestructorDecl _ ->
process_method_decl tenv cg cfg curr_class dec ~is_objc:false process_method_decl tenv cg cfg curr_class dec ~is_objc:false
| ObjCMethodDecl _ -> | ObjCMethodDecl _ ->
process_method_decl tenv cg cfg curr_class dec ~is_objc:true process_method_decl tenv cg cfg curr_class dec ~is_objc:true

@ -157,6 +157,7 @@ let method_signature_of_decl tenv meth_decl block_data_opt =
ms, fdi.Clang_ast_t.fdi_body, extra_instrs ms, fdi.Clang_ast_t.fdi_body, extra_instrs
| CXXMethodDecl (decl_info, name_info, tp, fdi, mdi), _ | CXXMethodDecl (decl_info, name_info, tp, fdi, mdi), _
| CXXConstructorDecl (decl_info, name_info, tp, fdi, mdi), _ | CXXConstructorDecl (decl_info, name_info, tp, fdi, mdi), _
| CXXConversionDecl (decl_info, name_info, tp, fdi, mdi), _
| CXXDestructorDecl (decl_info, name_info, tp, fdi, mdi), _ -> | CXXDestructorDecl (decl_info, name_info, tp, fdi, mdi), _ ->
let method_name = Ast_utils.get_unqualified_name name_info in let method_name = Ast_utils.get_unqualified_name name_info in
let class_name = Ast_utils.get_class_name_from_member name_info in let class_name = Ast_utils.get_class_name_from_member name_info in

@ -552,7 +552,8 @@ struct
| `Function -> function_deref_trans trans_state decl_ref | `Function -> function_deref_trans trans_state decl_ref
| `Var | `ImplicitParam | `ParmVar -> var_deref_trans trans_state stmt_info decl_ref | `Var | `ImplicitParam | `ParmVar -> var_deref_trans trans_state stmt_info decl_ref
| `Field | `ObjCIvar -> field_deref_trans trans_state stmt_info pre_trans_result decl_ref | `Field | `ObjCIvar -> field_deref_trans trans_state stmt_info pre_trans_result decl_ref
| `CXXMethod | `CXXConstructor -> method_deref_trans trans_state pre_trans_result decl_ref | `CXXMethod | `CXXConstructor | `CXXConversion ->
method_deref_trans trans_state pre_trans_result decl_ref
| _ -> | _ ->
let print_error decl_kind = let print_error decl_kind =
Printing.log_stats Printing.log_stats

@ -674,12 +674,12 @@ let get_decl_from_call_expr stmt =
| Some pointer -> Ast_utils.get_decl pointer | Some pointer -> Ast_utils.get_decl pointer
| _ -> None | _ -> None
let assign_default_params params_stmt call_stmt = let assign_default_params params_stmt call_stmt =
let open Clang_ast_t in let open Clang_ast_t in
match get_decl_from_call_expr call_stmt with match get_decl_from_call_expr call_stmt with
| Some FunctionDecl (_, name_info, _, fdecl_info) | Some FunctionDecl (_, name_info, _, fdecl_info)
| Some CXXMethodDecl (_, name_info, _, fdecl_info, _) | Some CXXMethodDecl (_, name_info, _, fdecl_info, _)
| Some CXXConversionDecl (_, name_info, _, fdecl_info, _)
| Some CXXConstructorDecl (_, name_info, _, fdecl_info, _) -> | Some CXXConstructorDecl (_, name_info, _, fdecl_info, _) ->
(let get_param_default_val param_decl = match param_decl with (let get_param_default_val param_decl = match param_decl with
| ParmVarDecl (_, _, _, var_decl_info) -> var_decl_info.vdi_init_expr | ParmVarDecl (_, _, _, var_decl_info) -> var_decl_info.vdi_init_expr

@ -117,6 +117,7 @@ let get_class_methods tenv class_name decl_list =
let process_method_decl = function let process_method_decl = function
| Clang_ast_t.CXXMethodDecl (decl_info, name_info, tp, function_decl_info, _) | Clang_ast_t.CXXMethodDecl (decl_info, name_info, tp, function_decl_info, _)
| Clang_ast_t.CXXConstructorDecl (decl_info, name_info, tp, function_decl_info, _) | Clang_ast_t.CXXConstructorDecl (decl_info, name_info, tp, function_decl_info, _)
| Clang_ast_t.CXXConversionDecl (decl_info, name_info, tp, function_decl_info, _)
| Clang_ast_t.CXXDestructorDecl (decl_info, name_info, tp, function_decl_info, _) -> | Clang_ast_t.CXXDestructorDecl (decl_info, name_info, tp, function_decl_info, _) ->
let method_name = name_info.Clang_ast_t.ni_name in let method_name = name_info.Clang_ast_t.ni_name in
Printing.log_out " ...Declaring method '%s'.\n" method_name; Printing.log_out " ...Declaring method '%s'.\n" method_name;

@ -0,0 +1,62 @@
/*
* 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 X {
operator int() { return f_; }
operator bool() { return b_; }
int f_;
bool b_;
X(int f, bool b) { f_ = f; b_ = b; }
X(const X& x) { f_ = x.f_; b_ = x.b_; }
};
struct Y {
// operator returning struct type
operator X() { return X(f,b); }
int f;
int b;
};
int branch_div0() {
X x(0, true);
if (x) {
int v = x;
return 1 / v;
}
return x;
}
int y_branch_div0() {
Y y;
y.f = 0;
y.b = true;
if ((X)y) {
int v = (X)y;
return 1 / v;
}
return (X)y;
}
int branch_no_div() {
X x(0, false);
if (x) {
int v = x;
return 1 / v;
}
return x;
}
int branch_div1() {
X x(1, true);
if (x) {
int v = x;
return 1 / v;
}
return x;
}

@ -0,0 +1,240 @@
digraph iCFG {
61 [label="61: DeclStmt \n _fun_X_X(&x:class X *,1:int ,1:_Bool ) [line 56]\n " shape="box"]
61 -> 56 ;
60 [label="60: DeclStmt \n n$3=_fun_X_operator int(&x:class X &) [line 58]\n *&v:int =n$3 [line 58]\n REMOVE_TEMPS(n$3); [line 58]\n " shape="box"]
60 -> 59 ;
59 [label="59: Return Stmt \n n$2=*&v:int [line 59]\n *&return:int =(1 / n$2) [line 59]\n REMOVE_TEMPS(n$2); [line 59]\n NULLIFY(&v,false); [line 59]\n NULLIFY(&x,false); [line 59]\n APPLY_ABSTRACTION; [line 59]\n " shape="box"]
59 -> 53 ;
58 [label="58: Prune (false branch) \n PRUNE((n$1 == 0), false); [line 57]\n REMOVE_TEMPS(n$1); [line 57]\n " shape="invhouse"]
58 -> 55 ;
57 [label="57: Prune (true branch) \n PRUNE((n$1 != 0), true); [line 57]\n REMOVE_TEMPS(n$1); [line 57]\n " shape="invhouse"]
57 -> 60 ;
56 [label="56: Call _fun_X_operator bool \n n$1=_fun_X_operator bool(&x:class X &) [line 57]\n " shape="box"]
56 -> 57 ;
56 -> 58 ;
55 [label="55: + \n " ]
55 -> 54 ;
54 [label="54: Return Stmt \n n$0=_fun_X_operator int(&x:class X &) [line 61]\n *&return:int =n$0 [line 61]\n REMOVE_TEMPS(n$0); [line 61]\n NULLIFY(&x,false); [line 61]\n APPLY_ABSTRACTION; [line 61]\n " shape="box"]
54 -> 53 ;
53 [label="53: Exit branch_div1 \n " color=yellow style=filled]
52 [label="52: Start branch_div1\nFormals: \nLocals: v:int x:class X \n DECLARE_LOCALS(&return,&v,&x); [line 55]\n NULLIFY(&v,false); [line 55]\n " color=yellow style=filled]
52 -> 61 ;
51 [label="51: DeclStmt \n _fun_X_X(&x:class X *,0:int ,0:_Bool ) [line 47]\n " shape="box"]
51 -> 46 ;
50 [label="50: DeclStmt \n n$3=_fun_X_operator int(&x:class X &) [line 49]\n *&v:int =n$3 [line 49]\n REMOVE_TEMPS(n$3); [line 49]\n " shape="box"]
50 -> 49 ;
49 [label="49: Return Stmt \n n$2=*&v:int [line 50]\n *&return:int =(1 / n$2) [line 50]\n REMOVE_TEMPS(n$2); [line 50]\n NULLIFY(&v,false); [line 50]\n NULLIFY(&x,false); [line 50]\n APPLY_ABSTRACTION; [line 50]\n " shape="box"]
49 -> 43 ;
48 [label="48: Prune (false branch) \n PRUNE((n$1 == 0), false); [line 48]\n REMOVE_TEMPS(n$1); [line 48]\n " shape="invhouse"]
48 -> 45 ;
47 [label="47: Prune (true branch) \n PRUNE((n$1 != 0), true); [line 48]\n REMOVE_TEMPS(n$1); [line 48]\n " shape="invhouse"]
47 -> 50 ;
46 [label="46: Call _fun_X_operator bool \n n$1=_fun_X_operator bool(&x:class X &) [line 48]\n " shape="box"]
46 -> 47 ;
46 -> 48 ;
45 [label="45: + \n " ]
45 -> 44 ;
44 [label="44: Return Stmt \n n$0=_fun_X_operator int(&x:class X &) [line 52]\n *&return:int =n$0 [line 52]\n REMOVE_TEMPS(n$0); [line 52]\n NULLIFY(&x,false); [line 52]\n APPLY_ABSTRACTION; [line 52]\n " shape="box"]
44 -> 43 ;
43 [label="43: Exit branch_no_div \n " color=yellow style=filled]
42 [label="42: Start branch_no_div\nFormals: \nLocals: v:int x:class X \n DECLARE_LOCALS(&return,&v,&x); [line 46]\n NULLIFY(&v,false); [line 46]\n " color=yellow style=filled]
42 -> 51 ;
41 [label="41: DeclStmt \n _fun_Y_Y(&y:class Y *) [line 36]\n " shape="box"]
41 -> 40 ;
40 [label="40: BinaryOperatorStmt: Assign \n *&y.f:int =0 [line 37]\n " shape="box"]
40 -> 39 ;
39 [label="39: BinaryOperatorStmt: Assign \n *&y.b:int =1 [line 38]\n " shape="box"]
39 -> 34 ;
38 [label="38: DeclStmt \n _fun_Y_operator X(&y:class Y &,&SIL_materialize_temp__n$10:class X *) [line 40]\n _fun_X_X(&__temp_construct_n$9:class X *,&SIL_materialize_temp__n$10:class X &) [line 40]\n n$12=_fun_X_operator int(&__temp_construct_n$9:class X &) [line 40]\n *&v:int =n$12 [line 40]\n REMOVE_TEMPS(n$12); [line 40]\n " shape="box"]
38 -> 37 ;
37 [label="37: Return Stmt \n n$8=*&v:int [line 41]\n *&return:int =(1 / n$8) [line 41]\n REMOVE_TEMPS(n$8); [line 41]\n NULLIFY(&v,false); [line 41]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 41]\n NULLIFY(&SIL_materialize_temp__n$10,false); [line 41]\n NULLIFY(&SIL_materialize_temp__n$5,false); [line 41]\n NULLIFY(&__temp_construct_n$0,false); [line 41]\n NULLIFY(&__temp_construct_n$4,false); [line 41]\n NULLIFY(&__temp_construct_n$9,false); [line 41]\n NULLIFY(&y,false); [line 41]\n APPLY_ABSTRACTION; [line 41]\n " shape="box"]
37 -> 31 ;
36 [label="36: Prune (false branch) \n PRUNE((n$7 == 0), false); [line 39]\n REMOVE_TEMPS(n$7); [line 39]\n " shape="invhouse"]
36 -> 33 ;
35 [label="35: Prune (true branch) \n PRUNE((n$7 != 0), true); [line 39]\n REMOVE_TEMPS(n$7); [line 39]\n " shape="invhouse"]
35 -> 38 ;
34 [label="34: Call _fun_X_operator bool \n _fun_Y_operator X(&y:class Y &,&SIL_materialize_temp__n$5:class X *) [line 39]\n _fun_X_X(&__temp_construct_n$4:class X *,&SIL_materialize_temp__n$5:class X &) [line 39]\n n$7=_fun_X_operator bool(&__temp_construct_n$4:class X &) [line 39]\n " shape="box"]
34 -> 35 ;
34 -> 36 ;
33 [label="33: + \n " ]
33 -> 32 ;
32 [label="32: Return Stmt \n _fun_Y_operator X(&y:class Y &,&SIL_materialize_temp__n$1:class X *) [line 43]\n _fun_X_X(&__temp_construct_n$0:class X *,&SIL_materialize_temp__n$1:class X &) [line 43]\n n$3=_fun_X_operator int(&__temp_construct_n$0:class X &) [line 43]\n *&return:int =n$3 [line 43]\n REMOVE_TEMPS(n$3); [line 43]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 43]\n NULLIFY(&SIL_materialize_temp__n$10,false); [line 43]\n NULLIFY(&SIL_materialize_temp__n$5,false); [line 43]\n NULLIFY(&__temp_construct_n$0,false); [line 43]\n NULLIFY(&__temp_construct_n$4,false); [line 43]\n NULLIFY(&__temp_construct_n$9,false); [line 43]\n NULLIFY(&y,false); [line 43]\n APPLY_ABSTRACTION; [line 43]\n " shape="box"]
32 -> 31 ;
31 [label="31: Exit y_branch_div0 \n " color=yellow style=filled]
30 [label="30: Start y_branch_div0\nFormals: \nLocals: __temp_construct_n$0:class X SIL_materialize_temp__n$1:class X __temp_construct_n$4:class X SIL_materialize_temp__n$5:class X v:int __temp_construct_n$9:class X SIL_materialize_temp__n$10:class X y:class Y \n DECLARE_LOCALS(&return,&__temp_construct_n$0,&SIL_materialize_temp__n$1,&__temp_construct_n$4,&SIL_materialize_temp__n$5,&v,&__temp_construct_n$9,&SIL_materialize_temp__n$10,&y); [line 35]\n NULLIFY(&v,false); [line 35]\n " color=yellow style=filled]
30 -> 41 ;
29 [label="29: DeclStmt \n _fun_X_X(&x:class X *,0:int ,1:_Bool ) [line 27]\n " shape="box"]
29 -> 24 ;
28 [label="28: DeclStmt \n n$3=_fun_X_operator int(&x:class X &) [line 29]\n *&v:int =n$3 [line 29]\n REMOVE_TEMPS(n$3); [line 29]\n " shape="box"]
28 -> 27 ;
27 [label="27: Return Stmt \n n$2=*&v:int [line 30]\n *&return:int =(1 / n$2) [line 30]\n REMOVE_TEMPS(n$2); [line 30]\n NULLIFY(&v,false); [line 30]\n NULLIFY(&x,false); [line 30]\n APPLY_ABSTRACTION; [line 30]\n " shape="box"]
27 -> 21 ;
26 [label="26: Prune (false branch) \n PRUNE((n$1 == 0), false); [line 28]\n REMOVE_TEMPS(n$1); [line 28]\n " shape="invhouse"]
26 -> 23 ;
25 [label="25: Prune (true branch) \n PRUNE((n$1 != 0), true); [line 28]\n REMOVE_TEMPS(n$1); [line 28]\n " shape="invhouse"]
25 -> 28 ;
24 [label="24: Call _fun_X_operator bool \n n$1=_fun_X_operator bool(&x:class X &) [line 28]\n " shape="box"]
24 -> 25 ;
24 -> 26 ;
23 [label="23: + \n " ]
23 -> 22 ;
22 [label="22: Return Stmt \n n$0=_fun_X_operator int(&x:class X &) [line 32]\n *&return:int =n$0 [line 32]\n REMOVE_TEMPS(n$0); [line 32]\n NULLIFY(&x,false); [line 32]\n APPLY_ABSTRACTION; [line 32]\n " shape="box"]
22 -> 21 ;
21 [label="21: Exit branch_div0 \n " color=yellow style=filled]
20 [label="20: Start branch_div0\nFormals: \nLocals: v:int x:class X \n DECLARE_LOCALS(&return,&v,&x); [line 26]\n NULLIFY(&v,false); [line 26]\n " color=yellow style=filled]
20 -> 29 ;
19 [label="19: Exit Y_Y \n " color=yellow style=filled]
18 [label="18: Start Y_Y\nFormals: this:class Y *\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n NULLIFY(&this,false); [line 19]\n " color=yellow style=filled]
18 -> 19 ;
17 [label="17: Return Stmt \n n$0=*&__return_param:void * [line 21]\n n$2=*&this:class Y * [line 21]\n n$3=*n$2.f:int [line 21]\n n$4=*&this:class Y * [line 21]\n n$5=*n$4.b:int [line 21]\n _fun_X_X(&SIL_materialize_temp__n$1:class X *,n$3:int ,n$5:_Bool ) [line 21]\n _fun_X_X(n$0:class X *,&SIL_materialize_temp__n$1:class X &) [line 21]\n REMOVE_TEMPS(n$0,n$2,n$3,n$4,n$5); [line 21]\n NULLIFY(&__return_param,false); [line 21]\n NULLIFY(&this,false); [line 21]\n NULLIFY(&SIL_materialize_temp__n$1,false); [line 21]\n APPLY_ABSTRACTION; [line 21]\n " shape="box"]
17 -> 16 ;
16 [label="16: Exit Y_operator X \n " color=yellow style=filled]
15 [label="15: Start Y_operator X\nFormals: this:class Y * __return_param:class X *\nLocals: SIL_materialize_temp__n$1:class X \n DECLARE_LOCALS(&return,&SIL_materialize_temp__n$1); [line 21]\n " color=yellow style=filled]
15 -> 17 ;
14 [label="14: BinaryOperatorStmt: Assign \n n$3=*&this:class X * [line 16]\n n$4=*&x:class X & [line 16]\n n$5=*n$4.f_:int [line 16]\n *n$3.f_:int =n$5 [line 16]\n REMOVE_TEMPS(n$3,n$4,n$5); [line 16]\n " shape="box"]
14 -> 13 ;
13 [label="13: BinaryOperatorStmt: Assign \n n$0=*&this:class X * [line 16]\n n$1=*&x:class X & [line 16]\n n$2=*n$1.b_:_Bool [line 16]\n *n$0.b_:_Bool =n$2 [line 16]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 16]\n NULLIFY(&this,false); [line 16]\n NULLIFY(&x,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"]
13 -> 12 ;
12 [label="12: Exit X_X \n " color=yellow style=filled]
11 [label="11: Start X_X\nFormals: this:class X * x:class X &\nLocals: \n DECLARE_LOCALS(&return); [line 16]\n " color=yellow style=filled]
11 -> 14 ;
10 [label="10: BinaryOperatorStmt: Assign \n n$2=*&this:class X * [line 15]\n n$3=*&f:int [line 15]\n *n$2.f_:int =n$3 [line 15]\n REMOVE_TEMPS(n$2,n$3); [line 15]\n NULLIFY(&f,false); [line 15]\n " shape="box"]
10 -> 9 ;
9 [label="9: BinaryOperatorStmt: Assign \n n$0=*&this:class X * [line 15]\n n$1=*&b:_Bool [line 15]\n *n$0.b_:_Bool =n$1 [line 15]\n REMOVE_TEMPS(n$0,n$1); [line 15]\n NULLIFY(&b,false); [line 15]\n NULLIFY(&this,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"]
9 -> 8 ;
8 [label="8: Exit X_X \n " color=yellow style=filled]
7 [label="7: Start X_X\nFormals: this:class X * f:int b:_Bool \nLocals: \n DECLARE_LOCALS(&return); [line 15]\n " color=yellow style=filled]
7 -> 10 ;
6 [label="6: Return Stmt \n n$0=*&this:class X * [line 12]\n n$1=*n$0.b_:_Bool [line 12]\n *&return:_Bool =n$1 [line 12]\n REMOVE_TEMPS(n$0,n$1); [line 12]\n NULLIFY(&this,false); [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"]
6 -> 5 ;
5 [label="5: Exit X_operator bool \n " color=yellow style=filled]
4 [label="4: Start X_operator bool\nFormals: this:class X *\nLocals: \n DECLARE_LOCALS(&return); [line 12]\n " color=yellow style=filled]
4 -> 6 ;
3 [label="3: Return Stmt \n n$0=*&this:class X * [line 11]\n n$1=*n$0.f_:int [line 11]\n *&return:int =n$1 [line 11]\n REMOVE_TEMPS(n$0,n$1); [line 11]\n NULLIFY(&this,false); [line 11]\n APPLY_ABSTRACTION; [line 11]\n " shape="box"]
3 -> 2 ;
2 [label="2: Exit X_operator int \n " color=yellow style=filled]
1 [label="1: Start X_operator int\nFormals: this:class X *\nLocals: \n DECLARE_LOCALS(&return); [line 11]\n " color=yellow style=filled]
1 -> 3 ;
}

@ -0,0 +1,64 @@
/*
* 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 ConversionOperatorTest {
public static final String FILE =
"infer/tests/codetoanalyze/cpp/frontend/methods/conversion_operator.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 = {
"branch_div0",
"y_branch_div0",
};
assertThat(
"Results should contain the expected divide by zero",
inferResults,
containsExactly(
DIVIDE_BY_ZERO,
FILE,
procedures
)
);
}
}

@ -64,4 +64,10 @@ public class MethodsTest {
throws InterruptedException, IOException, InferException { throws InterruptedException, IOException, InferException {
frontendTest("return_struct.cpp"); frontendTest("return_struct.cpp");
} }
@Test
public void testConversionOperatorDotFilesMatch()
throws InterruptedException, IOException, InferException {
frontendTest("conversion_operator.cpp");
}
} }

Loading…
Cancel
Save