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

    <tr>
        <th>Summary</th>
        <td>
            False positive in -Wthread-safety-analysis when returning scoped lock from function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics
      </td>
    </tr>

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

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

<pre>
    [D129755](https://reviews.llvm.org/D129755) uncovered issues in our handling of scoped locks at the end of a function, see the added test cases:
```c++
MutexLock lock() EXCLUSIVE_LOCK_FUNCTION(mutex) {
  return MutexLock(&mutex);
} // warning: mutex 'mutex' is still held at the end of function
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxdUk1v2zAM_TXyRUggy_HXwYc2aYBiWXvY2u1W0BIda1OkQJKT5d9PdtysHUDAFvnwyPfI1spLQ_L7TcrrMs9JviG86kM4epLdEb6N4fCk8OyXWp8OS-v2MfWO5jUdjLAndCip8n5AT5WhdnC0ByO1MntqO-qFPUaAtuK3pxBo6JGikWMJaBcZgrKG8DX1iFMRpIz4gD5QAR6nWdiGsDtSsGsIwu_HmLJfh4B_dpF9ahEFjIM9_FzvXr49vj687Z7XX962L0_r74_PT7F6GOEjhJQzAaUOw-AMvTFNJMU7kmQzkJQbenWFnsGZqC-ORidYzJczvoxeUB-U1rRHLf-TfBP8WVGCTVoUBWerIi8T2WSyzmpIggoamy1oj_RovQrqhKPHix-hdwhy4aHDcFmAAX3xse-5RzPLGe3_4D3tnD3c2ieD083nTe9V6Id2KewhPsZ1z5_F0dlfKEJ8Xpccf_JqVbGkb1jbiQphVWOVrhjjFXSS8VKkOTKRsjLR0KL2440RzoWGyTKpYG9stEhELh6vLlENZ5ynLK3TKiuzYplKVvAWRYZFW0NakRXDAyh9u8PENdNw7bD3saiVD_-ONAHv1d4gzo0BnDXHQfTowtwRhtBb13ysJJO8ZtL2F0rS_C8">