<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59662>59662</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Make thread safety analysis warnings be able to look through moves
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics,
            false-positive
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Weverything
      </td>
    </tr>
</table>

<pre>
    Using thread safety annotations with smart pointers:
```
#include <absl/synchronization/mutex.h>
#include <memory>

struct A {
 mutable
    absl::Mutex m;
};

void bar(std::unique_ptr<A> a)
ABSL_UNLOCK_FUNCTION(a->m) {
  a->m.Unlock();
}

void foo(std::unique_ptr<A> a)
ABSL_LOCKS_EXCLUDED(a->m) {
 a->m.Lock();
  bar(std::move(a));
}
```

Gives the following false positive:
```
<source>:18:3: warning: releasing mutex '#undefined->m' that was not held [-Wthread-safety-analysis]
 bar(std::move(a));
  ^
<source>:19:1: warning: mutex 'a->m' is still held at the end of function [-Wthread-safety-analysis]
}
^
<source>:17:8: note: mutex acquired here
  a->m.Lock();
       ^
2 warnings generated.
```

The analysis sees in function `foo` that `a->m` is locked, but since `bar` is called with moved value, it thinks that `std::move(a)->m` is unlocked. Looking through moves to equate `a` and `std::move(a)` would fix this issue.

Example in godbolt: https://godbolt.org/z/baGWGvGEz
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlVFv2zgMxz8N80IksKUmsR_84KZJcbhue9iK3VshW3SsqyxllpQ2_fQH2V7ay9rDrigU26LIH8m_JOGc2huiApbXsLyZieBb2xff6Uj9ybfK7GeVlafi3imzR9_2JCQ60ZA_oTDGeuGVNQ6flG_RdaL3eLDKeOod8BKSG0hKWCXT__jKuDK1DpIQ-EZUTgPbuZOp294a9TI4BLbrgqfnRQt8-96yjjrbn14nh9H5PtQeS4T19fgFu-BFpWl6Q8QhH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