<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 - [missed-optimization] compiler fails to de-virtualize within a single TU"
href="https://bugs.llvm.org/show_bug.cgi?id=41344">41344</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[missed-optimization] compiler fails to de-virtualize within a single TU
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>eyalroz@technion.ac.il
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Related StackOverflow question: <a href="https://stackoverflow.com/q/55464578/1593077">https://stackoverflow.com/q/55464578/1593077</a>
GodBolt example: <a href="https://godbolt.org/z/l0vdFG">https://godbolt.org/z/l0vdFG</a>
In the following code:
struct A {
virtual A& operator+=(const A& other) noexcept = 0;
};
void foo_inner(int *p) noexcept { *p += *p; }
void foo_virtual_inner(A *p) noexcept { *p += *p; }
void foo(int *p) noexcept
{
return foo_inner(p);
}
struct Aint : public A {
int i;
A& operator+=(const A& other) noexcept override final
{
i += dynamic_cast<const Aint&>(other).i;
// i += reinterpret_cast<const Aint&>(other).i;
return *this;
}
};
void foo_virtual(Aint *p) noexcept
{
return foo_virtual_inner(p);
}
Both functions, `foo()` and `foo_virtual()`, should compile to the same thing.
But clang++ 8.0.0 (and whatever GodBolt has as trunk), produces:
```
foo(int*): # @foo(int*)
shl dword ptr [rdi]
ret
foo_virtual(Aint*): # @foo_virtual(Aint*)
mov rax, qword ptr [rdi]
mov rax, qword ptr [rax]
mov rsi, rdi
jmp rax
```
i.e. clang++ doesn't manage to de-virtualize `Aint::operator+=` - although it
really should. It has all the necessary information AFAICT.</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>