From e07a20ea6d596042f4bf8f5df81dc6ba6704b394 Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Mon, 13 Nov 2017 03:05:39 -0800 Subject: [PATCH] [reporting] Report access path from the initial sink rather than the final sink. Summary: In a thread safety report we used the access path from the final sink. This diffs change the report to include the expanded access path from the initial sink. Reviewed By: sblackshear Differential Revision: D6297848 fbshipit-source-id: 2386063 --- infer/src/concurrency/RacerD.ml | 2 +- .../tests/codetoanalyze/cpp/racerd/issues.exp | 2 + .../codetoanalyze/cpp/racerd/reporting.cpp | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/cpp/racerd/reporting.cpp diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index c271ebe85..4cda31dc7 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -1169,7 +1169,7 @@ let report_thread_safety_violation tenv pdesc ~make_description ~report_kind acc let loc = CallSite.loc initial_sink_site in let ltr = make_trace ~report_kind path pdesc in (* what the potential bug is *) - let description = make_description pname final_sink_site initial_sink_site final_sink in + let description = make_description pname final_sink_site initial_sink_site initial_sink in (* why we are reporting it *) let issue_type, explanation = get_reporting_explanation report_kind tenv pname thread in let error_message = F.sprintf "%s%s" description explanation in diff --git a/infer/tests/codetoanalyze/cpp/racerd/issues.exp b/infer/tests/codetoanalyze/cpp/racerd/issues.exp index 391fcac19..b683fac38 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/issues.exp +++ b/infer/tests/codetoanalyze/cpp/racerd/issues.exp @@ -8,6 +8,8 @@ codetoanalyze/cpp/racerd/lock_guard.cpp, basics::LockGuard_get4, 0, LOCK_CONSIST codetoanalyze/cpp/racerd/lock_guard.cpp, basics::LockGuard_test1, 2, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read`,,access to `&this.suspiciously_read`] codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp, basics::LockGuardWithScope_get2, 3, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_written`,,access to `&this.suspiciously_written`] codetoanalyze/cpp/racerd/lock_guard_with_scope.cpp, basics::LockGuardWithScope_get4, 0, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read`,,access to `&this.suspiciously_read`] +codetoanalyze/cpp/racerd/reporting.cpp, reporting::Basic_call1, 1, LOCK_CONSISTENCY_VIOLATION, [,call to reporting::Basic_test,access to `&xparam.x1.w`,,call to reporting::Basic_call1,call to reporting::Basic_test,access to `&xparam.x1.w`] +codetoanalyze/cpp/racerd/reporting.cpp, reporting::Basic_test_unlock, 0, LOCK_CONSISTENCY_VIOLATION, [,call to reporting::Basic_call1,call to reporting::Basic_test,access to `&xparam.x1.w`,,call to reporting::Basic_call1,call to reporting::Basic_test,access to `&xparam.x1.w`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get2, 3, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_written1`,,access to `&this.suspiciously_written1`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get2, 4, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_written2`,,access to `&this.suspiciously_written2`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get4, 1, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read1`,,access to `&this.suspiciously_read1`] diff --git a/infer/tests/codetoanalyze/cpp/racerd/reporting.cpp b/infer/tests/codetoanalyze/cpp/racerd/reporting.cpp new file mode 100644 index 000000000..d27c0be6e --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/racerd/reporting.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include + +namespace reporting { + +struct X { + int w; + X* x1; +}; + +class Basic { + public: + Basic() {} + + void test(X& xparam) { xparam.x1->w++; } + + void call1() { + test(x); // race + } + + int test_lock() { + mutex_.lock(); + call1(); + } + + int test_unlock() { call1(); } + + private: + X x; + std::mutex mutex_; +}; +} // namespace reporting