From 6d562fc7b0a3c5c06eeba2eef396841926ae5e6b Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Wed, 30 Jan 2019 07:47:41 -0800 Subject: [PATCH] [dead store] Dead store false positive caused by forgetting expression inside decltype Summary: We do not want to export unnecessary information from clang plugin, hence, the solution to this false positive would be to annotate with `__unused__` attribute. Reviewed By: jvillard Differential Revision: D13861333 fbshipit-source-id: 774009f37 --- .../tests/codetoanalyze/cpp/liveness/dead_stores.cpp | 11 +++++++++++ infer/tests/codetoanalyze/cpp/liveness/issues.exp | 1 + 2 files changed, 12 insertions(+) diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index 6b269e993..a004cebb1 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -505,4 +505,15 @@ ChainedCalls chain_method_calls_ok() { return x.chained(5).chained(6); } +struct A { + int f : 4; +}; + +int decltype_read_ok_FP(int x) { + A a; // reports here as frontend forgets the expression used in decltype below + // a solution would be to annotate with __unused__ (T26148700) + decltype(a.f) i; + return x + i; +} + } // namespace dead_stores diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index 6671c398d..7edd4a1d7 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -8,6 +8,7 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_store_before_captu codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_struct_no_destructor_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_struct_rvalue_ref_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_then_live_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::decltype_read_ok_FP, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::easy_bad, 0, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_no_call_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_reassign_bad, 1, DEAD_STORE, no_bucket, ERROR, [Write of unused value]