Fix the return stmt that would not be the last instruction in the path in some cases

Reviewed By: akotulski

Differential Revision: D3372050

fbshipit-source-id: 959bff5
master
Dulma Churchill 9 years ago committed by Facebook Github Bot 4
parent 3a2a6c7c44
commit 5ed970efa9

@ -1911,10 +1911,10 @@ struct
if IList.length res_trans_stmt.root_nodes >0
then res_trans_stmt.root_nodes
else [ret_node] in
{ empty_res_trans with root_nodes = root_nodes_to_parent; leaf_nodes = [ret_node]}
{ empty_res_trans with root_nodes = root_nodes_to_parent; leaf_nodes = []}
| [] -> (* return; *)
let ret_node = mk_ret_node [] in
{ empty_res_trans with root_nodes = [ret_node]; leaf_nodes = [ret_node]}
{ empty_res_trans with root_nodes = [ret_node]; leaf_nodes = []}
| _ -> Printing.log_out
"\nWARNING: Missing translation of Return Expression. \
Return Statement ignored. Need fixing!\n";

@ -0,0 +1,57 @@
/*
* 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.
*/
#include <stdexcept>
#include <string>
class WrongParameterException : public std::runtime_error {
public:
WrongParameterException(bool e, const std::string& message)
: std::runtime_error(message){};
};
#define ENFORCE(e, ...) \
ENFORCE_CUSTOM(WrongParameterException, e, ##__VA_ARGS__)
#define ENFORCE_CUSTOM(exception, e, ...) \
({ \
auto const& _tmp = (e); \
_tmp ? _tmp : throw exception(#e, __VA_ARGS__); \
})
class Base {
virtual void dummy() {}
public:
int b;
};
class Derived : public Base {
public:
int a;
};
int cast_with_no_npe(Base& certificate) {
auto cert = dynamic_cast<Derived*>(&certificate);
ENFORCE(cert, "Base is not Derived");
return cert->a;
}
int cast_with_npe_avoided_by_enforce() {
Base base;
auto derived = dynamic_cast<Derived*>(&base);
ENFORCE(derived, "Base is not Derived");
return derived->a; // shouldn't result in NPE, even though it really is a
// problem
}
int cast_with_npe() {
Base base;
auto derived = dynamic_cast<Derived*>(&base);
return derived->a; // npe
}

@ -0,0 +1,438 @@
/* @generated */
digraph iCFG {
109 [label="109: DeclStmt \n _fun_Base_Base(&base:class Base *) [line 54]\n " shape="box"]
109 -> 108 ;
108 [label="108: DeclStmt \n n$2=_fun___cast(&base:class Base *,sizeof(class Derived ( sub )(cast)):void ) [line 55]\n *&derived:class Derived *=n$2 [line 55]\n " shape="box"]
108 -> 107 ;
107 [label="107: Return Stmt \n n$0=*&derived:class Derived * [line 56]\n n$1=*n$0.a:int [line 56]\n *&return:int =n$1 [line 56]\n " shape="box"]
107 -> 106 ;
106 [label="106: Exit cast_with_npe \n " color=yellow style=filled]
105 [label="105: Start cast_with_npe\nFormals: \nLocals: derived:class Derived * base:class Base \n DECLARE_LOCALS(&return,&derived,&base); [line 53]\n " color=yellow style=filled]
105 -> 109 ;
104 [label="104: DeclStmt \n _fun_Base_Base(&base:class Base *) [line 46]\n " shape="box"]
104 -> 103 ;
103 [label="103: DeclStmt \n n$11=_fun___cast(&base:class Base *,sizeof(class Derived ( sub )(cast)):void ) [line 47]\n *&derived:class Derived *=n$11 [line 47]\n " shape="box"]
103 -> 102 ;
102 [label="102: DeclStmt \n *&_tmp:class Derived *&=&derived [line 48]\n " shape="box"]
102 -> 97 ;
102 -> 98 ;
101 [label="101: ConditinalStmt Branch \n *&SIL_temp_conditional___n$2:class Derived *&=-1 [line 48]\n " shape="box"]
101 -> 96 ;
100 [label="100: Return Stmt \n _fun_std::__1::basic_string<char>_basic_string(&SIL_materialize_temp__n$7:class std::__1::basic_string<char> *,\"Base is not Derived\":char *) [line 48]\n _fun_WrongParameterException_WrongParameterException(&SIL_materialize_temp__n$6:class WrongParameterException *,\"derived\":_Bool ,&SIL_materialize_temp__n$7:class std::__1::basic_string<char> &) [line 48]\n _fun_WrongParameterException_WrongParameterException(&return:int *,&SIL_materialize_temp__n$6:class WrongParameterException &) [line 48]\n " shape="box"]
100 -> 94 ;
99 [label="99: ConditinalStmt Branch \n n$5=*&_tmp:class Derived *& [line 48]\n *&SIL_temp_conditional___n$2:class Derived *&=n$5 [line 48]\n " shape="box"]
99 -> 96 ;
98 [label="98: Prune (false branch) \n n$3=*&_tmp:class Derived *& [line 48]\n n$4=*n$3:class Derived * [line 48]\n PRUNE((n$4 == 0), false); [line 48]\n " shape="invhouse"]
98 -> 100 ;
97 [label="97: Prune (true branch) \n n$3=*&_tmp:class Derived *& [line 48]\n n$4=*n$3:class Derived * [line 48]\n PRUNE((n$4 != 0), true); [line 48]\n " shape="invhouse"]
97 -> 99 ;
96 [label="96: + \n " ]
96 -> 95 ;
95 [label="95: Return Stmt \n n$0=*&derived:class Derived * [line 49]\n n$1=*n$0.a:int [line 49]\n *&return:int =n$1 [line 49]\n " shape="box"]
95 -> 94 ;
94 [label="94: Exit cast_with_npe_avoided_by_enforce \n " color=yellow style=filled]
93 [label="93: Start cast_with_npe_avoided_by_enforce\nFormals: \nLocals: SIL_temp_conditional___n$2:class Derived *& SIL_materialize_temp__n$6:class WrongParameterException SIL_materialize_temp__n$7:class std::__1::basic_string<char> _tmp:class Derived *& derived:class Derived * base:class Base \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$2,&SIL_materialize_temp__n$6,&SIL_materialize_temp__n$7,&_tmp,&derived,&base); [line 45]\n " color=yellow style=filled]
93 -> 104 ;
92 [label="92: DeclStmt \n n$11=*&certificate:class Base & [line 40]\n n$12=_fun___cast(n$11:class Base *,sizeof(class Derived ( sub )(cast)):void ) [line 40]\n *&cert:class Derived *=n$12 [line 40]\n " shape="box"]
92 -> 91 ;
91 [label="91: DeclStmt \n *&_tmp:class Derived *&=&cert [line 41]\n " shape="box"]
91 -> 86 ;
91 -> 87 ;
90 [label="90: ConditinalStmt Branch \n *&SIL_temp_conditional___n$2:class Derived *&=-1 [line 41]\n " shape="box"]
90 -> 85 ;
89 [label="89: Return Stmt \n _fun_std::__1::basic_string<char>_basic_string(&SIL_materialize_temp__n$7:class std::__1::basic_string<char> *,\"Base is not Derived\":char *) [line 41]\n _fun_WrongParameterException_WrongParameterException(&SIL_materialize_temp__n$6:class WrongParameterException *,\"cert\":_Bool ,&SIL_materialize_temp__n$7:class std::__1::basic_string<char> &) [line 41]\n _fun_WrongParameterException_WrongParameterException(&return:int *,&SIL_materialize_temp__n$6:class WrongParameterException &) [line 41]\n " shape="box"]
89 -> 83 ;
88 [label="88: ConditinalStmt Branch \n n$5=*&_tmp:class Derived *& [line 41]\n *&SIL_temp_conditional___n$2:class Derived *&=n$5 [line 41]\n " shape="box"]
88 -> 85 ;
87 [label="87: Prune (false branch) \n n$3=*&_tmp:class Derived *& [line 41]\n n$4=*n$3:class Derived * [line 41]\n PRUNE((n$4 == 0), false); [line 41]\n " shape="invhouse"]
87 -> 89 ;
86 [label="86: Prune (true branch) \n n$3=*&_tmp:class Derived *& [line 41]\n n$4=*n$3:class Derived * [line 41]\n PRUNE((n$4 != 0), true); [line 41]\n " shape="invhouse"]
86 -> 88 ;
85 [label="85: + \n " ]
85 -> 84 ;
84 [label="84: Return Stmt \n n$0=*&cert:class Derived * [line 42]\n n$1=*n$0.a:int [line 42]\n *&return:int =n$1 [line 42]\n " shape="box"]
84 -> 83 ;
83 [label="83: Exit cast_with_no_npe \n " color=yellow style=filled]
82 [label="82: Start cast_with_no_npe\nFormals: certificate:class Base &\nLocals: SIL_temp_conditional___n$2:class Derived *& SIL_materialize_temp__n$6:class WrongParameterException SIL_materialize_temp__n$7:class std::__1::basic_string<char> _tmp:class Derived *& cert:class Derived * \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$2,&SIL_materialize_temp__n$6,&SIL_materialize_temp__n$7,&_tmp,&cert); [line 39]\n " color=yellow style=filled]
82 -> 92 ;
81 [label="81: Exit Base_Base \n " color=yellow style=filled]
80 [label="80: Start Base_Base\nFormals: this:class Base *\nLocals: \n DECLARE_LOCALS(&return); [line 28]\n " color=yellow style=filled]
80 -> 81 ;
79 [label="79: Exit Base_dummy \n " color=yellow style=filled]
78 [label="78: Start Base_dummy\nFormals: this:class Base *\nLocals: \n DECLARE_LOCALS(&return); [line 29]\n " color=yellow style=filled]
78 -> 79 ;
77 [label="77: Exit WrongParameterException_~WrongParameterException \n " color=yellow style=filled]
76 [label="76: Start WrongParameterException_~WrongParameterException\nFormals: this:class WrongParameterException *\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
76 -> 77 ;
75 [label="75: Constructor Init \n n$0=*&this:class WrongParameterException * [line 13]\n n$1=*&__param_0:class WrongParameterException & [line 13]\n _fun_std::runtime_error_runtime_error(n$0:class WrongParameterException *,n$1:class std::runtime_error &) [line 13]\n " shape="box"]
75 -> 74 ;
74 [label="74: Exit WrongParameterException_WrongParameterException \n " color=yellow style=filled]
73 [label="73: Start WrongParameterException_WrongParameterException\nFormals: this:class WrongParameterException * __param_0:class WrongParameterException &\nLocals: \n DECLARE_LOCALS(&return); [line 13]\n " color=yellow style=filled]
73 -> 75 ;
72 [label="72: Constructor Init \n n$0=*&this:class WrongParameterException * [line 16]\n n$1=*&message:class std::__1::basic_string<char> & [line 16]\n _fun_std::runtime_error_runtime_error(n$0:class WrongParameterException *,n$1:class std::__1::basic_string<char> &) [line 16]\n " shape="box"]
72 -> 71 ;
71 [label="71: Exit WrongParameterException_WrongParameterException \n " color=yellow style=filled]
70 [label="70: Start WrongParameterException_WrongParameterException\nFormals: this:class WrongParameterException * e:_Bool message:class std::__1::basic_string<char> &\nLocals: \n DECLARE_LOCALS(&return); [line 15]\n " color=yellow style=filled]
70 -> 72 ;
69 [label="69: DeclStmt \n n$21=*&__s1:char * [line 918]\n *&__r:char *=n$21 [line 918]\n " shape="box"]
69 -> 50 ;
68 [label="68: BinaryOperatorStmt: AddAssign \n n$19=*&__n:unsigned long [line 926]\n n$20=*&__s1:char * [line 926]\n *&__s1:char *=(n$20 + n$19) [line 926]\n " shape="box"]
68 -> 67 ;
67 [label="67: BinaryOperatorStmt: AddAssign \n n$17=*&__n:unsigned long [line 927]\n n$18=*&__s2:char * [line 927]\n *&__s2:char *=(n$18 + n$17) [line 927]\n " shape="box"]
67 -> 62 ;
66 [label="66: Call _fun_std::__1::char_traits<char32_t>_assign \n n$13=*&__s1:char * [line 929]\n *&__s1:char *=(n$13 - 1) [line 929]\n n$14=*&__s1:char * [line 929]\n n$15=*&__s2:char * [line 929]\n *&__s2:char *=(n$15 - 1) [line 929]\n n$16=*&__s2:char * [line 929]\n _fun_std::__1::char_traits<char32_t>_assign(n$14:char &,n$16:char &) [line 929]\n " shape="box"]
66 -> 63 ;
65 [label="65: Prune (false branch) \n n$12=*&__n:unsigned long [line 928]\n PRUNE((n$12 == 0), false); [line 928]\n " shape="invhouse"]
65 -> 58 ;
64 [label="64: Prune (true branch) \n n$12=*&__n:unsigned long [line 928]\n PRUNE((n$12 != 0), true); [line 928]\n " shape="invhouse"]
64 -> 66 ;
63 [label="63: UnaryOperator \n n$11=*&__n:unsigned long [line 928]\n *&__n:unsigned long =(n$11 - 1) [line 928]\n " shape="box"]
63 -> 62 ;
62 [label="62: + \n " ]
62 -> 64 ;
62 -> 65 ;
61 [label="61: Prune (false branch) \n PRUNE(((n$9 < n$10) == 0), false); [line 924]\n " shape="invhouse"]
61 -> 58 ;
60 [label="60: Prune (true branch) \n PRUNE(((n$9 < n$10) != 0), true); [line 924]\n " shape="invhouse"]
60 -> 68 ;
59 [label="59: BinaryOperatorStmt: LT \n n$9=*&__s2:char * [line 924]\n n$10=*&__s1:char * [line 924]\n " shape="box"]
59 -> 60 ;
59 -> 61 ;
58 [label="58: + \n " ]
58 -> 49 ;
57 [label="57: Call _fun_std::__1::char_traits<char32_t>_assign \n n$7=*&__s1:char * [line 922]\n n$8=*&__s2:char * [line 922]\n _fun_std::__1::char_traits<char32_t>_assign(n$7:char &,n$8:char &) [line 922]\n " shape="box"]
57 -> 54 ;
56 [label="56: Prune (false branch) \n n$6=*&__n:unsigned long [line 921]\n PRUNE((n$6 == 0), false); [line 921]\n " shape="invhouse"]
56 -> 49 ;
55 [label="55: Prune (true branch) \n n$6=*&__n:unsigned long [line 921]\n PRUNE((n$6 != 0), true); [line 921]\n " shape="invhouse"]
55 -> 57 ;
54 [label="54: BinaryOperatorStmt: Comma \n n$3=*&__n:unsigned long [line 921]\n *&__n:unsigned long =(n$3 - 1) [line 921]\n n$4=*&__s1:char * [line 921]\n *&__s1:char *=(n$4 + 1) [line 921]\n n$5=*&__s2:char * [line 921]\n *&__s2:char *=(n$5 + 1) [line 921]\n " shape="box"]
54 -> 53 ;
53 [label="53: + \n " ]
53 -> 55 ;
53 -> 56 ;
52 [label="52: Prune (false branch) \n PRUNE(((n$1 < n$2) == 0), false); [line 919]\n " shape="invhouse"]
52 -> 59 ;
51 [label="51: Prune (true branch) \n PRUNE(((n$1 < n$2) != 0), true); [line 919]\n " shape="invhouse"]
51 -> 53 ;
50 [label="50: BinaryOperatorStmt: LT \n n$1=*&__s1:char * [line 919]\n n$2=*&__s2:char * [line 919]\n " shape="box"]
50 -> 51 ;
50 -> 52 ;
49 [label="49: + \n " ]
49 -> 48 ;
48 [label="48: Return Stmt \n n$0=*&__r:char * [line 931]\n *&return:char *=n$0 [line 931]\n " shape="box"]
48 -> 47 ;
47 [label="47: Exit std::__1::char_traits<char32_t>_move \n " color=yellow style=filled]
46 [label="46: Start std::__1::char_traits<char32_t>_move\nFormals: __s1:char * __s2:char * __n:unsigned long \nLocals: __r:char * \n DECLARE_LOCALS(&return,&__r); [line 914]\n " color=yellow style=filled]
46 -> 69 ;
45 [label="45: DeclStmt \n n$21=*&__s1:char * [line 799]\n *&__r:char *=n$21 [line 799]\n " shape="box"]
45 -> 26 ;
44 [label="44: BinaryOperatorStmt: AddAssign \n n$19=*&__n:unsigned long [line 807]\n n$20=*&__s1:char * [line 807]\n *&__s1:char *=(n$20 + n$19) [line 807]\n " shape="box"]
44 -> 43 ;
43 [label="43: BinaryOperatorStmt: AddAssign \n n$17=*&__n:unsigned long [line 808]\n n$18=*&__s2:char * [line 808]\n *&__s2:char *=(n$18 + n$17) [line 808]\n " shape="box"]
43 -> 38 ;
42 [label="42: Call _fun_std::__1::char_traits<char16_t>_assign \n n$13=*&__s1:char * [line 810]\n *&__s1:char *=(n$13 - 1) [line 810]\n n$14=*&__s1:char * [line 810]\n n$15=*&__s2:char * [line 810]\n *&__s2:char *=(n$15 - 1) [line 810]\n n$16=*&__s2:char * [line 810]\n _fun_std::__1::char_traits<char16_t>_assign(n$14:char &,n$16:char &) [line 810]\n " shape="box"]
42 -> 39 ;
41 [label="41: Prune (false branch) \n n$12=*&__n:unsigned long [line 809]\n PRUNE((n$12 == 0), false); [line 809]\n " shape="invhouse"]
41 -> 34 ;
40 [label="40: Prune (true branch) \n n$12=*&__n:unsigned long [line 809]\n PRUNE((n$12 != 0), true); [line 809]\n " shape="invhouse"]
40 -> 42 ;
39 [label="39: UnaryOperator \n n$11=*&__n:unsigned long [line 809]\n *&__n:unsigned long =(n$11 - 1) [line 809]\n " shape="box"]
39 -> 38 ;
38 [label="38: + \n " ]
38 -> 40 ;
38 -> 41 ;
37 [label="37: Prune (false branch) \n PRUNE(((n$9 < n$10) == 0), false); [line 805]\n " shape="invhouse"]
37 -> 34 ;
36 [label="36: Prune (true branch) \n PRUNE(((n$9 < n$10) != 0), true); [line 805]\n " shape="invhouse"]
36 -> 44 ;
35 [label="35: BinaryOperatorStmt: LT \n n$9=*&__s2:char * [line 805]\n n$10=*&__s1:char * [line 805]\n " shape="box"]
35 -> 36 ;
35 -> 37 ;
34 [label="34: + \n " ]
34 -> 25 ;
33 [label="33: Call _fun_std::__1::char_traits<char16_t>_assign \n n$7=*&__s1:char * [line 803]\n n$8=*&__s2:char * [line 803]\n _fun_std::__1::char_traits<char16_t>_assign(n$7:char &,n$8:char &) [line 803]\n " shape="box"]
33 -> 30 ;
32 [label="32: Prune (false branch) \n n$6=*&__n:unsigned long [line 802]\n PRUNE((n$6 == 0), false); [line 802]\n " shape="invhouse"]
32 -> 25 ;
31 [label="31: Prune (true branch) \n n$6=*&__n:unsigned long [line 802]\n PRUNE((n$6 != 0), true); [line 802]\n " shape="invhouse"]
31 -> 33 ;
30 [label="30: BinaryOperatorStmt: Comma \n n$3=*&__n:unsigned long [line 802]\n *&__n:unsigned long =(n$3 - 1) [line 802]\n n$4=*&__s1:char * [line 802]\n *&__s1:char *=(n$4 + 1) [line 802]\n n$5=*&__s2:char * [line 802]\n *&__s2:char *=(n$5 + 1) [line 802]\n " shape="box"]
30 -> 29 ;
29 [label="29: + \n " ]
29 -> 31 ;
29 -> 32 ;
28 [label="28: Prune (false branch) \n PRUNE(((n$1 < n$2) == 0), false); [line 800]\n " shape="invhouse"]
28 -> 35 ;
27 [label="27: Prune (true branch) \n PRUNE(((n$1 < n$2) != 0), true); [line 800]\n " shape="invhouse"]
27 -> 29 ;
26 [label="26: BinaryOperatorStmt: LT \n n$1=*&__s1:char * [line 800]\n n$2=*&__s2:char * [line 800]\n " shape="box"]
26 -> 27 ;
26 -> 28 ;
25 [label="25: + \n " ]
25 -> 24 ;
24 [label="24: Return Stmt \n n$0=*&__r:char * [line 812]\n *&return:char *=n$0 [line 812]\n " shape="box"]
24 -> 23 ;
23 [label="23: Exit std::__1::char_traits<char16_t>_move \n " color=yellow style=filled]
22 [label="22: Start std::__1::char_traits<char16_t>_move\nFormals: __s1:char * __s2:char * __n:unsigned long \nLocals: __r:char * \n DECLARE_LOCALS(&return,&__r); [line 795]\n " color=yellow style=filled]
22 -> 45 ;
21 [label="21: Return Stmt \n n$7=*&SIL_temp_conditional___n$0:char * [line 694]\n *&return:char *=n$7 [line 694]\n " shape="box"]
21 -> 14 ;
20 [label="20: ConditinalStmt Branch \n n$3=*&__s1:char * [line 694]\n n$4=*&__s2:char * [line 694]\n n$5=*&__n:unsigned long [line 694]\n n$6=_fun_wmemmove(n$3:char *,n$4:char *,n$5:unsigned long ) [line 694]\n *&SIL_temp_conditional___n$0:char *=n$6 [line 694]\n " shape="box"]
20 -> 15 ;
19 [label="19: ConditinalStmt Branch \n n$2=*&__s1:char * [line 694]\n *&SIL_temp_conditional___n$0:char *=n$2 [line 694]\n " shape="box"]
19 -> 15 ;
18 [label="18: Prune (false branch) \n PRUNE(((n$1 == 0) == 0), false); [line 694]\n " shape="invhouse"]
18 -> 20 ;
17 [label="17: Prune (true branch) \n PRUNE(((n$1 == 0) != 0), true); [line 694]\n " shape="invhouse"]
17 -> 19 ;
16 [label="16: BinaryOperatorStmt: EQ \n n$1=*&__n:unsigned long [line 694]\n " shape="box"]
16 -> 17 ;
16 -> 18 ;
15 [label="15: + \n " ]
15 -> 21 ;
14 [label="14: Exit std::__1::char_traits<wchar_t>_move \n " color=yellow style=filled]
13 [label="13: Start std::__1::char_traits<wchar_t>_move\nFormals: __s1:char * __s2:char * __n:unsigned long \nLocals: SIL_temp_conditional___n$0:char * \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$0); [line 693]\n " color=yellow style=filled]
13 -> 16 ;
12 [label="12: Return Stmt \n n$7=*&SIL_temp_conditional___n$0:char * [line 648]\n *&return:char *=n$7 [line 648]\n " shape="box"]
12 -> 5 ;
11 [label="11: ConditinalStmt Branch \n n$3=*&__s1:char * [line 648]\n n$4=*&__s2:char * [line 648]\n n$5=*&__n:unsigned long [line 648]\n n$6=_fun_memmove(n$3:void *,n$4:void *,n$5:unsigned long ) [line 648]\n *&SIL_temp_conditional___n$0:char *=n$6 [line 648]\n " shape="box"]
11 -> 6 ;
10 [label="10: ConditinalStmt Branch \n n$2=*&__s1:char * [line 648]\n *&SIL_temp_conditional___n$0:char *=n$2 [line 648]\n " shape="box"]
10 -> 6 ;
9 [label="9: Prune (false branch) \n PRUNE(((n$1 == 0) == 0), false); [line 648]\n " shape="invhouse"]
9 -> 11 ;
8 [label="8: Prune (true branch) \n PRUNE(((n$1 == 0) != 0), true); [line 648]\n " shape="invhouse"]
8 -> 10 ;
7 [label="7: BinaryOperatorStmt: EQ \n n$1=*&__n:unsigned long [line 648]\n " shape="box"]
7 -> 8 ;
7 -> 9 ;
6 [label="6: + \n " ]
6 -> 12 ;
5 [label="5: Exit std::__1::char_traits<char>_move \n " color=yellow style=filled]
4 [label="4: Start std::__1::char_traits<char>_move\nFormals: __s1:char * __s2:char * __n:unsigned long \nLocals: SIL_temp_conditional___n$0:char * \n DECLARE_LOCALS(&return,&SIL_temp_conditional___n$0); [line 647]\n " color=yellow style=filled]
4 -> 7 ;
3 [label="3: Call _fun_infer_model::AbortWhenRun___infer_skip__ \n n$0=*&this:class infer_model::AbortWhenRun * [line 19]\n n$1=*n$0:class infer_model::AbortWhenRun [line 19]\n _fun_infer_model::AbortWhenRun___infer_skip__(n$0:class infer_model::AbortWhenRun *) [line 19]\n " shape="box"]
3 -> 2 ;
2 [label="2: Exit infer_model::AbortWhenRun_AbortWhenRun \n " color=yellow style=filled]
1 [label="1: Start infer_model::AbortWhenRun_AbortWhenRun\nFormals: this:class infer_model::AbortWhenRun *\nLocals: \n DECLARE_LOCALS(&return); [line 19]\n " color=yellow style=filled]
1 -> 3 ;
}

@ -0,0 +1,63 @@
/*
* Copyright (c) 2015 - 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.ResultContainsErrorInMethod.contains;
import static utils.matchers.ResultContainsExactly.containsExactly;
import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain;
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 NoNPEAfterDynamicCastTest {
public static final String FILE =
"infer/tests/codetoanalyze/cpp/errors/subtyping/cast_with_enforce.cpp";
private static ImmutableList<String> inferCmd;
public static final String NULL_DEREFERENCE = "NULL_DEREFERENCE";
@ClassRule
public static DebuggableTemporaryFolder folder =
new DebuggableTemporaryFolder();
@BeforeClass
public static void runInfer() throws InterruptedException, IOException {
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
}
@Test
public void whenInferRunsOnCast_with_no_npeThenNoNPEFound()
throws InterruptedException, IOException, InferException {
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
String[] procedures = {"cast_with_npe"};
assertThat(
"Results should not contain " + NULL_DEREFERENCE,
inferResults,
containsExactly(
NULL_DEREFERENCE,
FILE,
procedures
)
);
}
}

@ -0,0 +1,37 @@
/*
* Copyright (c) 2013 - 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 frontend.cpp;
import org.junit.Rule;
import org.junit.Test;
import java.io.IOException;
import utils.DebuggableTemporaryFolder;
import utils.InferException;
import utils.ClangFrontendUtils;
public class SubtypingTest {
String basePath = "infer/tests/codetoanalyze/cpp/errors/subtyping/";
@Rule
public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException {
ClangFrontendUtils.createAndCompareCppDotFiles(folder, basePath + fileRelative);
}
@Test
public void testSimpleDotFilesMatch()
throws InterruptedException, IOException, InferException {
frontendTest("cast_with_enforce.cpp");
}
}
Loading…
Cancel
Save