From 84cfd0a450e0be6fe8107da9c9153e603b25f5dd Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Fri, 20 Jul 2018 03:27:24 -0700 Subject: [PATCH] [frontend] Do not create exceptional successors for return nodes Summary: Exceptional successors were not meant to be created for return nodes, but they were created if try block had a single return statement. Reviewed By: jvillard Differential Revision: D8913371 fbshipit-source-id: 6ac85b21d --- infer/src/clang/cTrans.ml | 8 +++++++- .../codetoanalyze/cpp/liveness/dead_stores.cpp | 2 +- infer/tests/codetoanalyze/cpp/liveness/issues.exp | 1 + infer/tests/codetoanalyze/cpp/ownership/returns.cpp | 13 +++++++++++++ .../cpp/shared/exceptions/Exceptions.cpp.dot | 1 - 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 31d0d2bf9..bb4a56e5e 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -1909,8 +1909,14 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s try_control.root_nodes else try_control.leaf_nodes in + (* do not add exceptional successors to return nodes *) List.iter - ~f:(fun try_end -> Procdesc.set_succs_exn_only try_end catch_start_nodes) + ~f:(fun try_end -> + match Procdesc.Node.get_kind try_end with + | Procdesc.Node.Stmt_node "Return Stmt" -> + () + | _ -> + Procdesc.set_succs_exn_only try_end catch_start_nodes ) try_ends ; try_trans_result | _ -> diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index efc618953..3faac942e 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -388,7 +388,7 @@ class Exceptions { return 0; } - int FN_unreachable_catch_bad() { + int unreachable_catch_bad() { int i = 1; try { } catch (...) { diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index 302a6cc61..2a8fd1d86 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -1,5 +1,6 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions_FP_read_in_catch_tricky_ok, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions_dead_in_catch_bad, 4, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions_unreachable_catch_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::FP_assign_array_tricky_ok, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::capture_by_value_bad, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_pointer_bad, 2, DEAD_STORE, no_bucket, ERROR, [Write of unused value] diff --git a/infer/tests/codetoanalyze/cpp/ownership/returns.cpp b/infer/tests/codetoanalyze/cpp/ownership/returns.cpp index e9346bb6e..fc6f990f1 100644 --- a/infer/tests/codetoanalyze/cpp/ownership/returns.cpp +++ b/infer/tests/codetoanalyze/cpp/ownership/returns.cpp @@ -128,4 +128,17 @@ const char* return_nullptr2_ok() { return local; } +struct A { + ~A(); +}; + +int try_catch_return_ok() { + A a; + try { + return 1; + } catch (...) { + return 2; + } +} + } // namespace returns diff --git a/infer/tests/codetoanalyze/cpp/shared/exceptions/Exceptions.cpp.dot b/infer/tests/codetoanalyze/cpp/shared/exceptions/Exceptions.cpp.dot index 0e64d9bfc..4eeb948c2 100644 --- a/infer/tests/codetoanalyze/cpp/shared/exceptions/Exceptions.cpp.dot +++ b/infer/tests/codetoanalyze/cpp/shared/exceptions/Exceptions.cpp.dot @@ -193,7 +193,6 @@ digraph cfg { "main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ; - "main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_4" [color="red" ]; "main.fad58de7366495db4650cfefac2fcd61_4" [label="4: Return Stmt \n *&return:int=-1 [line 76, column 5]\n " shape="box"]