<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54316>54316</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
missing increment in SmartLock::try_lock for an MT-only lock in non-MT build
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Smattr
</td>
</tr>
</table>
<pre>
[`lllvm::sys::SmartMutex`](https://github.com/llvm/llvm-project/blob/93d1a623cecb6f732db7900baf230a13e6ac6c6a/llvm/include/llvm/Support/Mutex.h#L28) uses an `acquired` counter for debugging. `try_lock` appears to forget to increment `acquired`:
```cpp
bool try_lock() {
if (!mt_only || llvm_is_multithreaded())
return impl.try_lock();
else return true; // ← this branch should ++acquired
}
```
It seems this will lead to an assertion failure during `unlock` of one of these mutexes that was acquired via `try_lock`.
Apologies I don't have a crashing test case reproducer, but this looks like a pretty straightforward typo.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVMlu2zAQ_Rr6MoggUbYsH3TI0gIBklNyNyhybLGhSJVLUv99h3Sd7VZhII7I0Zs3G0enTgPb3LCuNsa8zqy9JgmncFaeZuHjY4r4hwzY5o7xfopxKaf8J8lRxymNlXQzfRSA83K1ePcLZaTP0biRll2rGtHxVqIcu8O25Wrc7up6FAfe1qJpsROyk534wNFWmqTwY-MpLYvzGbNQqibG2wfeM76DFDCAsEA0hfydtEdFKkiXbEQPB-dB4ZiOR22PVbaK_rQ3Tr5kK7EsKHyA6LLhEWPWyLvHGW38hplDr-9YfXnTThG5LOcdKM_onIF3J2eSbHvz2QRAH6AcNXPcO2tOZHFLAjnevQ77OZlICfYoFPkuIFm-YAB4jMlb0PNiqq8eWfvNIZqAF_voE5IBnAsJ7Adnfcd2NcRJBxi9sHKCMLlkFNnckLxn4RMm2959S8Tn7NxHCIhzOGO-aWPAUDA5v1QsEQL6qJ2Fg9AmeQSVPBUoZzzZS3XcAZzFvMQJif6ca48ZUkR4E1T2f7TgVYtvpa0-k7lenHFHTb_eg3KW8W2ESbwiCJBehCl7jhgiSFGyRC2skkTP-C2MKZ5jMM690Fu_5N8WSmU8QYhe6OMUqXnehKfoTourVmpo1a7diRWV0OAw6xCyh4--0hbKfD1krmXcLsxLv1KCHp-vSluUPTK3zl49PhMZbdQqeTP89zASiYSBlM26bbrVNHS9ag6j7Pt13-42vB0PvFOyaYRsNq2q5cqIkbqm3BGcW3yDAkE6XQcrPfCa87pt6rqpm3VdNWtUIzb92Mmmb9YtW9c4U3GrzKOi4Vr5oVCiWQx0aHSI4eOQOkIfLWJxR_gixcn5gdIUo18Vz0Nh_heeinzM">