<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/156760>156760</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] False positive mutex '...' is still held at the end of function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PiJoules
</td>
</tr>
</table>
<pre>
```
#include <mutex>
std::mutex m0, m1;
void func() {
std::unique_lock ul1(m0, std::defer_lock);
std::unique_lock ul2(m1, std::defer_lock);
std::lock(ul1, ul2);
}
```
```
$ ~/misc/clang-cipd-latest/bin/clang++ -c -Wall -Wthread-safety /tmp/test.cc
/tmp/test.cc:9:1: warning: mutex 'ul1' is still held at the end of function [-Wthread-safety-analysis]
9 | }
| ^
/tmp/test.cc:8:3: note: mutex acquired here
8 | std::lock(ul1, ul2);
| ^
/tmp/test.cc:9:1: warning: mutex 'ul2' is still held at the end of function [-Wthread-safety-analysis]
9 | }
| ^
/tmp/test.cc:8:3: note: mutex acquired here
8 | std::lock(ul1, ul2);
| ^
2 warnings generated.
```
This comes up with https://github.com/llvm/llvm-project/pull/154078/. Both mutexes should be unlocked by the `unique_lock` dtors at the end of the function. Also `-Wthread-safety-analysis` is incorrectly saying `ul1` and `ul2` are mutexes.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVD2P4zYQ_TWjZmBBGn1YKlTIu6ciVYoAVwYUOWsxoUWfSO7FTX57QOq8u9hkcZd0MQya5PDNx3vjEc7p88o8QHOC5jETwS92G37WP9lg2GWzVbcB2uLbtxiBKr1KExQjVA-X4PkPqD5FQzE6r6AaoRrTNV4KoAe8lFCddvuz1QqfwiqBOqAe4RgNiC-4sOovgX81Vv6OwZRA3e7j5YHiJ96SHajf_X4Ipwgvvwt_Me7XXYr7sOO_vYHjY1zfsvDuSDX-CTRdtJNAkzRiPR-kvqqDEZ6dB5pmvd4tQCegEx4kHj4LY_Dw2S8bC3Vw4on9DYEmf7nGlZ3PpUwB3l1VYw_VWEI14lexrXo9x-3OO9AxFXFE7dB5bQwubBQKj35h5FWhfUo6eG1XhOb0LoODWIW5Oe2geUwMI0axHnAnYt82n_45rw6qsYrJrNbza1JCfgl6Y4ULb_zNaZc8_YAAmD7xMX4c-DuE0P-GEPxvlNC9cIdnXnkTnlX-9779ZdEOpb2ww3DFr9ovuHh_dTEgTUDTWfslzLm0F6DJmOf7z-G62d9Yxma-BmOAprKpi2MHNOV4sn7ZC2OHbrHBKJwZwxorYIXzLVENbfHmTwptgcrbzb1TIm7vauQ4Gmcj8ENN2iLqqldpt42lNzd04qbXc4pmymgXq9pPlE4b33PNMzVUqq96kfFQHpu2r-r-WGbLUNb9TD3T3DL1PYladaopi1nUsq5npTI9UEFN0RcVldRXZd50XSlVx2VXtLIuO6gLvght8shebrdzpp0LPJRNe2yLzIiZjUuDl8joWe5zAYjiIN6GxPkczg7qwmjn3asfr71JI_sNrHnESRjHeLVOe_3Mr82f5_mPNn8WNjP8635IdbnUEam054H-CgAA__8YgOfW">