llvm-project
c1e17e59 - [ThreadSafety] Ignore parameter destructors (#170843)

Commit
35 days ago
[ThreadSafety] Ignore parameter destructors (#170843) Fixes a false positive in thread safety analysis when function parameters have lock/unlock annotations in their constructor/destructor. PR #169320 added destructors to the CFG, which introduced false positives in thread safety analysis for function parameters. According to [expr.call#6](https://eel.is/c++draft/expr.call#6), parameter initialization occurs in the caller's context while destruction occurs in the callee's context. ```cpp class A { public: A() EXCLUSIVE_LOCK_FUNCTION(mu_) { mu_.Lock(); } ~A() UNLOCK_FUNCTION(mu_) { mu_.Unlock(); } private: Mutex mu_; }; int do_something(A a) { // Previously: false positive warning return 0; } ``` Previously, thread safety analysis would see the destructor (unlock) in `do_something` but not the corresponding constructor (lock) that happened in the caller's context, causing a false positive.
Author
Parents
Loading