<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 - Incorrect code generated when references are used with ||"
href="https://bugs.llvm.org/show_bug.cgi?id=37663">37663</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect code generated when references are used with ||
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>anand.shankar.k@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following two functions have identical semantics. Only when x is false
should y be dereferenced. Incorrect code is generated for the first function.
int foo1(int x, int& y, int size)
{
if (x || y < size)
return x;
return size;
}
int foo2(int x, int* y, int size)
{
if (x || *y < size)
return x;
return size;
}
Code via compiler explorer (with -O2) shows that for foo1, y is always
dereferenced.
_Z4foo1iRii: # @_Z4foo1iRii
cmpl %edx, (%rsi) # y is dereferenced
cmovll %edi, %edx
testl %edi, %edi
cmovnel %edi, %edx
movl %edx, %eax
retq
_Z4foo2iPii: # @_Z4foo2iPii
testl %edi, %edi
je .LBB1_1
movl %edi, %eax
retq
.LBB1_1:
xorl %eax, %eax
cmpl %edx, (%rsi)
cmovgel %edx, %eax
retq</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>