[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
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 759fddc7e8
commit 7b8145b8bc

@ -683,6 +683,9 @@ let should_report_on_proc tenv procdesc =
|| (not (PredSymb.equal_access (Procdesc.get_access procdesc) Private)) || (not (PredSymb.equal_access (Procdesc.get_access procdesc) Private))
&& (not (Procname.Java.is_autogen_method java_pname)) && (not (Procname.Java.is_autogen_method java_pname))
&& not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting) && 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 _} -> | ObjC_Cpp {kind= CPPMethod _ | CPPConstructor _ | CPPDestructor _} ->
not (PredSymb.equal_access (Procdesc.get_access procdesc) Private) not (PredSymb.equal_access (Procdesc.get_access procdesc) Private)
| ObjC_Cpp {kind= ObjCClassMethod | ObjCInstanceMethod | ObjCInternalMethod; class_name} -> | ObjC_Cpp {kind= ObjCClassMethod | ObjCInstanceMethod | ObjCInternalMethod; class_name} ->

@ -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 <mutex>
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_;
};
Loading…
Cancel
Save