[clang] Thread Safety Analysis: Differentiate between lock sets at real join points and expected/actual sets at function end (PR #105526)

Mike Hommey via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 19:48:54 PDT 2024


glandium wrote:

Before this change the following (reduced) code didn't emit a warning, but now does:
```
class __attribute__((capability("mutex"))) StaticMutex {
 public:
  void Lock() __attribute__((exclusive_lock_function()))  { /* unimplemented */ }

  void Unlock() __attribute__((unlock_function())) { /* unimplemented */ }

  void AssertCurrentThreadOwns() __attribute__((assert_capability(this))) {
  }
};

class __attribute__((scoped_lockable)) StaticMutexAutoLock {
 public:
  explicit StaticMutexAutoLock(StaticMutex& aLock) __attribute__((exclusive_lock_function(aLock))) { /* unimplemented */ }

  ~StaticMutexAutoLock(void) __attribute__((unlock_function())) { /* unimplemented */ }
};

class __attribute__((scoped_lockable)) StaticMutexAutoUnlock {
 public:
  explicit StaticMutexAutoUnlock(StaticMutex& aLock) __attribute__((release_capability(aLock))) { /* unimplemented */ }

  ~StaticMutexAutoUnlock() __attribute__((release_capability())) { /* unimplemented */ }
};

StaticMutex sMutex;

bool InitPreferredSampleRate() {
  sMutex.AssertCurrentThreadOwns();
  {
    StaticMutexAutoUnlock unlock(sMutex);
  }
  return true;
}
```

Now it says `warning: mutex 'sMutex' is still held at the end of function [-Wthread-safety-analysis]` because apparently it's not "propagating" from the attribute on AssertCurrentThreadOwns?

https://github.com/llvm/llvm-project/pull/105526


More information about the cfe-commits mailing list