<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 - Optimization introduces error when right shifting by integer width."
href="https://bugs.llvm.org/show_bug.cgi?id=33578">33578</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimization introduces error when right shifting by integer width.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>d.horne@danielhorne.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>I have the following inline, to simulate a rotl instruction:
static uint64_t rotateLeft(uint64_t x, int n)
{
return ((x << n) | (x >> (64 - n)));
}
It produces the expected results on MSVC, GCC, and clang++ with optimisation
switched off, but somehow produces 4294967295 in the n=0 case with -O3
optimisations. The results for n>0 look ok.
I then made the following tests:
printf(" 6 << 0 = %u \n", 6<<0);
printf(" 6 >> (64-0) = %u \n", 6>>(64-0));
printf(" 6 >> 64 = %u \n", 6>>64);
printf("((6 << 0) | (6 >> (64 - 0))) = %u \n", ((6 << 0) | (6 >> (64 -
0))));
printf(" rotateLeft(6,0) = %u \n", rotateLeft(6,0));
which produced:
6 << 0 = 6
6 >> (64-0) = 24579104
6 >> 64 = 24579104
((6 << 0) | (6 >> (64 - 0))) = 4294967295
indicating the problem shows up when right shifting by 64..
According to the c++11 spec, right shifts should produce "the integral part of
the quotient of E1 / 2^E2", which in this case is zero, leading me to consider
this a compliance bug.</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>