<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - distinct subclass types aliasing false-positive"
href="https://llvm.org/bugs/show_bug.cgi?id=22986">22986</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>distinct subclass types aliasing false-positive
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.6
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>drfuchs@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Pointers to distinct subclass types can't alias, even if they share a base
class.
But the code generated here indicates clang thinks they can, as it doesn't
collapse the return expression into a constant 4 (and even re-fetches
t1->common):
struct base {int common;};
struct sub1 : base {} *t1;
struct sub2 : base {} *t2;
int fn(void)
{
t1->common = 1;
t2->common = 2;
return t1->common + 3;
}
Compiled -O3, this generates:
fn(): # @fn()
movq t1(%rip), %rax
movl $1, (%rax)
movq t2(%rip), %rcx
movl $2, (%rcx)
movl (%rax), %eax
addl $3, %eax
retq
vs. GCC's:
fn():
movq t1(%rip), %rax
movl $1, (%rax)
movq t2(%rip), %rax
movl $2, (%rax)
movl $4, %eax
ret
Note that it doesn't matter that the two subclasses had the same layout; the
exact same code is generated even if they're different:
struct base {int common;};
struct sub1 : base {int foo;} *t1;
struct sub2 : base {char bar;} *t2;</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>