From 4065b1d120eabbc8c39835a6c13b4b535e668361 Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 1 Sep 2017 10:14:05 -0700 Subject: [PATCH] [dead stores] recognize lambdas with `auto` parameter Summary: When a lambda has an `auto` parameter, the inferred type of the parameter because part of the name. Our heuristic for identifying lambda was checking if the lambda's name was exactly `operator()`, which won't catch this case. Reviewed By: jvillard Differential Revision: D5753323 fbshipit-source-id: 85ff75a --- infer/src/checkers/liveness.ml | 2 +- infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp | 6 ++++++ infer/tests/codetoanalyze/cpp/liveness/issues.exp | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/infer/src/checkers/liveness.ml b/infer/src/checkers/liveness.ml index 79a0598f5..b8914e03f 100644 --- a/infer/src/checkers/liveness.ml +++ b/infer/src/checkers/liveness.ml @@ -66,7 +66,7 @@ let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary = in let procname = Procdesc.get_proc_name proc_desc in let is_cpp_lambda = - match Typ.Procname.get_method procname with "operator()" -> true | _ -> false + String.is_substring ~substring:"operator()" (Typ.Procname.get_method procname) in let is_captured_var pvar = let pvar_name = Pvar.get_name pvar in diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index e43edc9dd..cb3c49ab2 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -122,6 +122,12 @@ void by_ref1_ok(int& ref) { ref = 7; } void by_ref2_ok(int& ref) { ref++; } +int capture_by_ref3_ok() { + int x = 0; + [&](auto y) { x += y; }(3); + return x; +} + int plus_plus_ok() { int x = 0; return ++x; diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index d0edf956c..5b7742869 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -4,7 +4,7 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_then_live_bad, 1, codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::easy_bad, 0, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_no_call_bad, 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::init_capture_reassign_bad, 1, DEAD_STORE, [Write of unused value] -codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::lambda_bad::lambda_dead_stores.cpp:139:11_operator(), 1, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::lambda_bad::lambda_dead_stores.cpp:145:11_operator(), 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus1_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus2_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus3_bad, 2, DEAD_STORE, [Write of unused value]