Never call destructor on delete expression

Summary:
This call was producing confusing false positives when deleted object was possible to be null.
Changing frontend to add that check is not trivial so I turned it off for now (we don't handle
destructors in other cases anyway)

Reviewed By: dulmarod

Differential Revision: D3509354

fbshipit-source-id: c23dc81
master
Andrzej Kotulski 9 years ago committed by Facebook Github Bot 8
parent 84311acb13
commit 9b07a3e762

@ -2134,6 +2134,11 @@ struct
let result_trans_param = exec_with_self_exception instruction trans_state_param param in
let exp = extract_exp_from_list result_trans_param.exps
"WARNING: There should be one expression to delete. \n" in
let call_instr = Sil.Call ([], (Sil.Const (Sil.Cfun fname)), [exp], sil_loc, Sil.cf_default) in
let call_res_trans = { empty_res_trans with instrs = [call_instr] } in
let all_res_trans = if false then
(* FIXME (t10135167): call destructor on deleted pointer if it's not null *)
(* Right now it's dead code hidden by the 'false' flag *)
let deleted_type = delete_expr_info.Clang_ast_t.xdei_destroyed_type in
(* create stmt_info with new pointer so that destructor call doesn't create a node *)
let destruct_stmt_info = { stmt_info with
@ -2143,10 +2148,11 @@ struct
let this_res_trans_destruct = { empty_res_trans with exps = result_trans_param.exps } in
let destruct_res_trans = cxx_destructor_call_trans trans_state_pri destruct_stmt_info
this_res_trans_destruct deleted_type in
(* function is void *)
let call_instr = Sil.Call ([], (Sil.Const (Sil.Cfun fname)), [exp], sil_loc, Sil.cf_default) in
let call_res_trans = { empty_res_trans with instrs = [call_instr] } in
let all_res_trans = [ result_trans_param; destruct_res_trans; call_res_trans] in
[ result_trans_param; destruct_res_trans; call_res_trans]
(* --- END OF DEAD CODE --- *)
else
[ result_trans_param; call_res_trans] in
let res_trans = PriorityNode.compute_results_to_parent trans_state_pri sil_loc
"Call delete" stmt_info all_res_trans in
{ res_trans with exps = [] }

@ -11,7 +11,7 @@ digraph iCFG {
6 -> 8 ;
5 [label="5: Call delete \n n$0=*&x:class X * [line 14]\n n$1=*n$0:class X [line 14]\n _fun_X_~X(n$0:class X *) [line 14]\n _fun___delete(n$0:class X *) [line 14]\n " shape="box"]
5 [label="5: Call delete \n n$0=*&x:class X * [line 14]\n _fun___delete(n$0:class X *) [line 14]\n " shape="box"]
5 -> 4 ;

@ -1,10 +1,10 @@
/* @generated */
digraph iCFG {
53 [label="53: DeclStmt \n n$2=_fun___new(sizeof(class Triangle ):unsigned long ) [line 71]\n _fun_Triangle_Triangle(n$2:class Triangle *) [line 71]\n *&trgl:class Triangle *=n$2 [line 71]\n " shape="box"]
53 [label="53: DeclStmt \n n$1=_fun___new(sizeof(class Triangle ):unsigned long ) [line 71]\n _fun_Triangle_Triangle(n$1:class Triangle *) [line 71]\n *&trgl:class Triangle *=n$1 [line 71]\n " shape="box"]
53 -> 52 ;
52 [label="52: Call delete \n n$0=*&trgl:class Polygon * [line 72]\n n$1=*n$0:class Polygon [line 72]\n _fun_Polygon_~Polygon(n$0:class Polygon *) virtual [line 72]\n _fun___delete(n$0:class Polygon *) [line 72]\n " shape="box"]
52 [label="52: Call delete \n n$0=*&trgl:class Polygon * [line 72]\n _fun___delete(n$0:class Polygon *) [line 72]\n " shape="box"]
52 -> 51 ;

Loading…
Cancel
Save