Skip to content

[racerd][starvation] pair accesses and locks whose root types differ only in qualifiers - #2167

Open
VladimirMakaev wants to merge 1 commit into
meta:mainfrom
VladimirMakaev:concurrency-const-this
Open

VladimirMakaev wants to merge 1 commit into
meta:mainfrom
VladimirMakaev:concurrency-const-this

Conversation

@VladimirMakaev

@VladimirMakaev VladimirMakaev commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

The clang frontend types this as C const * in the const methods of C and as C * elsewhere.
RacerD and Starvation compared these types with their qualifiers when pairing accesses or locks of
two methods, missing races and deadlocks involving const methods:

#include <mutex>

class C {
  std::mutex m_;
  int x_;

 public:
  int get() const { return x_; } // Infer missed: LOCK_CONSISTENCY_VIOLATION
  void set(int v) {
    std::lock_guard<std::mutex> l(m_);
    x_ = v;
  }
};

RacerD now ignores the base type when grouping accesses, as AccessPath.compare does. Starvation
compares the root types of parameter-rooted locks across threads modulo qualifiers, so const C *
parameters also pair with C * ones.

Trade-off: two-instance deadlocks with const on one side only, such as x.copy_from(&y) against
y.copy_to(&x), are no longer reported, like the same code without const.

Test plan

New tests cpp/racerd/const_methods.cpp and cpp/starvation/const_methods.cpp. Of their _bad
cases, main reports only the two-instance deadlock FN_copy_from_bad, which is no longer
reported. All codetoanalyze tests pass.

@meta-cla meta-cla Bot added the CLA Signed label Oct 2, 2026

@ngorogiannis ngorogiannis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@VladimirMakaev
VladimirMakaev force-pushed the concurrency-const-this branch from a026f87 to 023807b Compare October 3, 2026 20:12
@VladimirMakaev VladimirMakaev changed the title [DRAFT] [racerd][starvation] pair const methods with the other methods of a class [DRAFT] [racerd][starvation] pair accesses and locks whose root types differ only in qualifiers Oct 3, 2026
@VladimirMakaev
VladimirMakaev force-pushed the concurrency-const-this branch from 023807b to 8ecc034 Compare October 5, 2026 06:53
VladimirMakaev added a commit to VladimirMakaev/infer that referenced this pull request Oct 5, 2026
…only in qualifiers

The clang frontend types `this` as `C const *` in the const methods of `C` and as `C *` elsewhere.
RacerD and Starvation compared these types with their qualifiers when pairing accesses or locks of
two methods, missing races and deadlocks involving const methods:

Expectation conflicts with earlier frontier commits were resolved automatically in: infer/tests/codetoanalyze/cpp/racerd/issues.exp

Upstream-PR: meta#2167
PR-Head: 8ecc034
PR-Base: 9cc2641
@VladimirMakaev
VladimirMakaev force-pushed the concurrency-const-this branch from 8ecc034 to b56ace7 Compare October 7, 2026 15:55
@VladimirMakaev

Copy link
Copy Markdown
Contributor Author

Will reopen once current PR queue is cleared

…only in qualifiers

The clang frontend types `this` as `C const *` in the const methods of `C` and as `C *` elsewhere.
RacerD and Starvation compared these types with their qualifiers when pairing accesses or locks of
two methods, missing races and deadlocks involving const methods:

```cpp
#include <mutex>

class C {
  std::mutex m_;
  int x_;

 public:
  int get() const { return x_; } // Infer missed: LOCK_CONSISTENCY_VIOLATION
  void set(int v) {
    std::lock_guard<std::mutex> l(m_);
    x_ = v;
  }
};
```

RacerD now ignores the base type when grouping accesses, as `AccessPath.compare` does. Starvation
compares the root types of parameter-rooted locks across threads modulo qualifiers, so `const C *`
parameters also pair with `C *` ones.

Trade-off: two-instance deadlocks with const on one side only, such as `x.copy_from(&y)` against
`y.copy_to(&x)`, are no longer reported, like the same code without const.

## Test plan

New tests `cpp/racerd/const_methods.cpp` and `cpp/starvation/const_methods.cpp`. Of their `_bad`
cases, main reports only the two-instance deadlock `FN_copy_from_bad`, which is no longer
reported. All codetoanalyze tests pass.
@VladimirMakaev
VladimirMakaev marked this pull request as ready for review November 5, 2026 14:56
@VladimirMakaev VladimirMakaev changed the title [DRAFT] [racerd][starvation] pair accesses and locks whose root types differ only in qualifiers [racerd][starvation] pair accesses and locks whose root types differ only in qualifiers Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants