From ff475e43e46b13f665914d15b79bc32d6c707e36 Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Mon, 6 Nov 2017 09:37:52 -0800 Subject: [PATCH] [LockConsistency] Do not merge read/write with container read/write Summary: We were conflating reads/writes with container reads/writes that created false positives. Reviewed By: sblackshear Differential Revision: D6232768 fbshipit-source-id: 39159cb --- infer/src/concurrency/RacerD.ml | 7 +++-- .../codetoanalyze/cpp/racerd/containers.cpp | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/racerd/containers.cpp diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index b2679a810..5602d562a 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -1524,10 +1524,11 @@ module SyntacticQuotientedAccessListMap : QuotientedAccessListMap = struct let compare (x: t) (y: t) = match (x, y) with - | ( (Read ap1 | Write ap1 | ContainerRead (ap1, _) | ContainerWrite (ap1, _)) - , (Read ap2 | Write ap2 | ContainerRead (ap2, _) | ContainerWrite (ap2, _)) ) -> + | (Read ap1 | Write ap1), (Read ap2 | Write ap2) + | ( (ContainerRead (ap1, _) | ContainerWrite (ap1, _)) + , (ContainerRead (ap2, _) | ContainerWrite (ap2, _)) ) -> [%compare : (_var * Typ.t) * AccessPath.access list] ap1 ap2 - | InterfaceCall _, _ | _, InterfaceCall _ -> + | (InterfaceCall _ | Read _ | Write _ | ContainerRead _ | ContainerWrite _), _ -> RacerDDomain.Access.compare x y end) diff --git a/infer/tests/codetoanalyze/cpp/racerd/containers.cpp b/infer/tests/codetoanalyze/cpp/racerd/containers.cpp new file mode 100644 index 000000000..07cd11295 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/racerd/containers.cpp @@ -0,0 +1,31 @@ +/* + * 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 +#include + +namespace containers { + +struct A { + int value; +}; + +struct B { + + void access_container_and_contents_ok(int key, int value) { + int s = map.size(); + mutex_.lock(); + map[key].value = value; + } + + private: + std::map map; + std::mutex mutex_; +}; +} // namespace containers