<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] failure to drop unused libstdc++ std::string"
href="https://bugs.llvm.org/show_bug.cgi?id=45287">45287</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[missed optimization] failure to drop unused libstdc++ std::string
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>(GodBolt example: <a href="https://godbolt.org/z/rbkRSJ">https://godbolt.org/z/rbkRSJ</a>)
Consider the following program:
#include <string>
void foo() {
std::string s { "This is not a small string" };
}
If we compile this with clang++ and libc++, we get:
foo():
ret
but if we use libstdc++, we get:
foo():
sub rsp, 40
lea rax, [rsp + 24]
mov qword ptr [rsp + 8], rax
mov edi, 27
call operator new(unsigned long)
mov qword ptr [rsp + 8], rax
mov qword ptr [rsp + 24], 26
movups xmm0, xmmword ptr [rip + .L.str+10]
movups xmmword ptr [rax + 10], xmm0
movups xmm0, xmmword ptr [rip + .L.str]
movups xmmword ptr [rax], xmm0
mov qword ptr [rsp + 16], 26
mov byte ptr [rax + 26], 0
mov rdi, rax
call operator delete(void*)
add rsp, 40
ret
mov rdi, rax
call _Unwind_Resume
.L.str:
.asciz "This is not a small string"
Yikes! What's going on here? Can't clang++/LLVM notice an unused string without
some libc++ special sauce? Is it the new/delete pair that's exotic somehow?
It seems that the hint is at the bottom "call _Unwind_Resume". James Garret
notes (in comments on this related SO answer:
<a href="https://stackoverflow.com/a/60820696/1593077">https://stackoverflow.com/a/60820696/1593077</a>) that libstdc++'s std::string code
apparently has some try/catch somewhere which LLVM can't optimize away, because
of <a class="bz_bug_link
bz_status_NEW "
title="NEW - Optimize away exception allocation and throws handled by catch"
href="show_bug.cgi?id=35052">bug 35052</a>. So, marking this as dependent on that one - and pinging you LLVM
devs to give it some much needed attention...</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>