[clang] Thread Safety Analysis: Graduate ACQUIRED_BEFORE() and ACQUIRED_AFTER() from beta features (PR #152853)

Aaron Puchert via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 7 13:22:41 PDT 2025


aaronpuchert wrote:

The behavior of before/after is a bit weird in some cases, but I guess it's mostly used within the same class where it should be fine. Unlike the rest of the analysis, it doesn't work with expressions but strips them down to the bare `FieldDecl` or `VarDecl`. This has some weird side effects:

```c++
class Data {
public:
	Mutex mu;
};

class ContainsData {
	Data d1, d2;
	Mutex lm ACQUIRED_AFTER(d1.mu);

	void f() {
		lm.Lock();
		d1.mu.Lock();    // Warning: mutex 'mu' must be acquired before 'lm' - Ok.
		d1.mu.Unlock();
		d2.mu.Lock();    // Warning: mutex 'mu' must be acquired before 'lm' - False positive.
		d2.mu.Unlock();
		lm.Unlock();
	}
};
```

But I guess we can also fix that later.

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


More information about the cfe-commits mailing list