From 7b8145b8bcb0da7f837aebeae53ac3459d774ab9 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 18 Jan 2021 07:55:55 -0800 Subject: [PATCH] [racerd][C++] do not report on lambdas at top level Summary: Lambdas are essentially private (but are not marked as such in Infer), so we should only report on their non-private callers. Meanwhile, add a test to document that access propagation to those callers is currently broken. Reviewed By: da319 Differential Revision: D25944811 fbshipit-source-id: ef8ca6d9c --- infer/src/concurrency/RacerD.ml | 3 ++ .../codetoanalyze/cpp/racerd/lambdas.cpp | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 infer/tests/codetoanalyze/cpp/racerd/lambdas.cpp diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index b1f20cf0a..e33447f7e 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -683,6 +683,9 @@ let should_report_on_proc tenv procdesc = || (not (PredSymb.equal_access (Procdesc.get_access procdesc) Private)) && (not (Procname.Java.is_autogen_method java_pname)) && not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting) + | ObjC_Cpp objc_cpp when Procname.ObjC_Cpp.is_cpp_lambda objc_cpp -> + (* do not report on lambdas; they are essentially private though do not appear as such *) + false | ObjC_Cpp {kind= CPPMethod _ | CPPConstructor _ | CPPDestructor _} -> not (PredSymb.equal_access (Procdesc.get_access procdesc) Private) | ObjC_Cpp {kind= ObjCClassMethod | ObjCInstanceMethod | ObjCInternalMethod; class_name} -> diff --git a/infer/tests/codetoanalyze/cpp/racerd/lambdas.cpp b/infer/tests/codetoanalyze/cpp/racerd/lambdas.cpp new file mode 100644 index 000000000..50d37da92 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/racerd/lambdas.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +class Lambdas { + public: + void race_in_lambda_even_without_call_ok() { + auto lambda_with_sync = [&]() { + mutex_.lock(); + f = 0; + mutex_.unlock(); + return f; + }; + } + + // access propagation to callees does not currently work + int FN_race_in_lambda_bad() { + auto lambda_with_sync = [&]() { return g; }; + + return lambda_with_sync(); + } + + void set_under_lock(int value) { + mutex_.lock(); + g = value; + mutex_.unlock(); + } + + private: + int f; + int g; + std::mutex mutex_; +};