From a947961d76fc9982d619228db879084a24ca7094 Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Tue, 30 Mar 2021 03:15:24 -0700 Subject: [PATCH] [deadstore] False positive caused by exceptional cfg Summary: The title Also notice that there is a duplication of an error. Reviewed By: skcho Differential Revision: D27426933 fbshipit-source-id: dbd2f861a --- .../codetoanalyze/cpp/liveness/dead_stores.cpp | 14 ++++++++++++++ infer/tests/codetoanalyze/cpp/liveness/issues.exp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index bc21f9076..9b522b0cd 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -539,6 +539,20 @@ class Exceptions { return 3; } + int return_in_try_in_for_ok() { + constexpr int i1 = 3; + for (int i = 1;; ++i) { + try { + return maybe_throw(); + } catch (const char* msg) { + if (i1 == i) { + return 2; + } + } + } + return 3; + } + int read_in_catch_ok() { int x; try { diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index 3a0113669..54d9f0b65 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -1,6 +1,8 @@ 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::not_read_in_catch_bad, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions::read_only_in_catch_bad, 5, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions::return_in_try_in_for_ok, 2, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::Exceptions::return_in_try_in_for_ok, 2, 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_tricky2_ok, 3, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::binaryConditional_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value]