From a4b87a0951fc42c2de37215b1effbe1ddea291db Mon Sep 17 00:00:00 2001 From: Dulma Rodriguez Date: Thu, 10 Mar 2016 06:37:32 -0800 Subject: [PATCH] Translate destructor calls Reviewed By: akotulski Differential Revision: D3035382 fb-gh-sync-id: 3dba93e shipit-source-id: 3dba93e --- infer/src/clang/cTrans.ml | 2 +- .../cpp/frontend/destructors/call_destructor.cpp | 15 +++++++++++++++ .../frontend/destructors/call_destructor.cpp.dot | 13 +++++++++++++ infer/tests/frontend/cpp/DestructorsTest.java | 6 ++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp.dot diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index d6ca76776..e46274af2 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -597,7 +597,7 @@ struct | `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 ~is_constructor_init - | `CXXMethod | `CXXConversion | `CXXConstructor -> + | `CXXMethod | `CXXConversion | `CXXConstructor | `CXXDestructor -> method_deref_trans trans_state pre_trans_result decl_ref stmt_info decl_kind | _ -> let print_error decl_kind = diff --git a/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp b/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp new file mode 100644 index 000000000..874c56cf8 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp @@ -0,0 +1,15 @@ +/* + * 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 Person { + int age; + ~Person(); +}; + +void f(Person* p) { p->Person::~Person(); } diff --git a/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp.dot new file mode 100644 index 000000000..33b9a271a --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/destructors/call_destructor.cpp.dot @@ -0,0 +1,13 @@ +digraph iCFG { +3 [label="3: Call _fun_Person_~Person \n n$0=*&p:class Person * [line 15]\n n$1=*n$0:class Person [line 15]\n _fun_Person_~Person(n$0:class Person *) [line 15]\n REMOVE_TEMPS(n$0,n$1); [line 15]\n NULLIFY(&p,false); [line 15]\n APPLY_ABSTRACTION; [line 15]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit f \n " color=yellow style=filled] + + +1 [label="1: Start f\nFormals: p:class Person *\nLocals: \n DECLARE_LOCALS(&return); [line 15]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/frontend/cpp/DestructorsTest.java b/infer/tests/frontend/cpp/DestructorsTest.java index 13409afaf..ee5205055 100644 --- a/infer/tests/frontend/cpp/DestructorsTest.java +++ b/infer/tests/frontend/cpp/DestructorsTest.java @@ -46,4 +46,10 @@ public class DestructorsTest { throws InterruptedException, IOException, InferException { frontendTest("pseudo_destructor_expr.cpp"); } + + @Test + public void testCallOnCallDestructorDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("call_destructor.cpp"); + } }