diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index ce99224d4..b815aef21 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -88,7 +88,10 @@ module TransferFunctions (CFG : ProcCfg.S) = struct fun pname -> QualifiedCppName.Match.match_qualifiers matcher (Typ.Procname.get_qualifiers pname) and is_cpp_trylock = - let matcher = QualifiedCppName.Match.of_fuzzy_qual_names ["std::unique_lock::owns_lock"] in + let matcher = + QualifiedCppName.Match.of_fuzzy_qual_names + ["std::unique_lock::owns_lock"; "std::unique_lock::try_lock"] + in fun pname -> QualifiedCppName.Match.match_qualifiers matcher (Typ.Procname.get_qualifiers pname) in diff --git a/infer/tests/codetoanalyze/cpp/racerd/issues.exp b/infer/tests/codetoanalyze/cpp/racerd/issues.exp index c12a10cac..391fcac19 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/issues.exp +++ b/infer/tests/codetoanalyze/cpp/racerd/issues.exp @@ -13,3 +13,4 @@ codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get2, 4, LOCK_CONSI codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get4, 1, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read1`,,access to `&this.suspiciously_read1`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get4, 2, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read2`,,access to `&this.suspiciously_read2`] codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get5, 5, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read1`,,access to `&this.suspiciously_read1`] +codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get6, 5, LOCK_CONSISTENCY_VIOLATION, [,access to `&this.suspiciously_read1`,,access to `&this.suspiciously_read1`] diff --git a/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp b/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp index c85ca1fb8..7a3d98874 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp +++ b/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp @@ -67,6 +67,15 @@ class UniqueLock { } } + int get6() { + std::unique_lock lock(mutex_, std::defer_lock); + if (lock.try_lock()) { + return well_guarded1; + } else { + return suspiciously_read1; + } + } + private: int well_guarded1; int suspiciously_read1;