diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index 6d35b0786..89bee8cf8 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -87,6 +87,10 @@ module TransferFunctions (CFG : ProcCfg.S) = struct in 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 + fun pname -> + QualifiedCppName.Match.match_qualifiers matcher (Typ.Procname.get_qualifiers pname) in fun pname actuals -> match pname with @@ -121,6 +125,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct Lock | Typ.Procname.ObjC_Cpp _ as pname when is_cpp_unlock pname -> Unlock + | Typ.Procname.ObjC_Cpp _ as pname when is_cpp_trylock pname -> + LockedIfTrue | pname when Typ.Procname.equal pname BuiltinDecl.__set_locked_attribute -> Lock | pname when Typ.Procname.equal pname BuiltinDecl.__delete_locked_attribute -> diff --git a/infer/tests/codetoanalyze/cpp/racerd/issues.exp b/infer/tests/codetoanalyze/cpp/racerd/issues.exp index 2c8ea044a..c12a10cac 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/issues.exp +++ b/infer/tests/codetoanalyze/cpp/racerd/issues.exp @@ -12,3 +12,4 @@ codetoanalyze/cpp/racerd/unique_lock.cpp, basics::UniqueLock_get2, 3, LOCK_CONSI 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`] 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`] diff --git a/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp b/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp index 059049476..c85ca1fb8 100644 --- a/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp +++ b/infer/tests/codetoanalyze/cpp/racerd/unique_lock.cpp @@ -58,6 +58,15 @@ class UniqueLock { return result + suspiciously_read2; } + int get5() { + std::unique_lock lock(mutex_, std::try_to_lock); + if (lock.owns_lock()) { + return well_guarded1; + } else { + return suspiciously_read1; + } + } + private: int well_guarded1; int suspiciously_read1;