<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Bit-wise rather than logical ‘and’ for decremented size_type in __hash_table gives unsigned integer overflow warning"
href="https://bugs.llvm.org/show_bug.cgi?id=38606">38606</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Bit-wise rather than logical ‘and’ for decremented size_type in __hash_table gives unsigned integer overflow warning
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>flash@pobox.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>The Undefined Behavior Sanitizer with unsigned-integer-overflow enabled
complains about the following code in
<a href="https://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table">https://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table</a>:
2251 __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
…
2255 else if (__n & (__n - 1))
The bit-wise rather than logical ‘and’, to produce a Boolean, on an unsigned
value which is being decremented, strikes me as poor style if not simply a
mistake. It also prevents short-circiting, which might mitigate any
performance hit to correcting this.
This is of course not actually undefined behavior, since decrementing an
unsigned zero is defined to be a large positive value. But I’ve seen dozens of
incorrect unsigned decrementing bugs detected by static analysis, and never a
serious need to use unsigneds as elements of modular arithmetic rather than as
a risky approximation to genuine integers. So this sanitizer option strikes me
as worthwhile, but silencing the warning for this usage was fairly inconvenient
for our build system.
This would not have inconvenienced us if PR 25706 had been implemented, but
it seems not to have been, despite the resolution.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>