<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 - std::to_string with constant input not optimized to string constant"
href="https://bugs.llvm.org/show_bug.cgi?id=31994">31994</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::to_string with constant input not optimized to string constant
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>trass3r@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>#include <string>
std::string foo() {
return std::to_string(5u);
}
$ clang++ -S -O3 -std=c++14
foo[abi:cxx11](): # @foo[abi:cxx11]()
push rbx
mov rbx, rdi
mov esi, vsnprintf
mov edx, 16
mov ecx, .L.str
mov r8d, 5
xor eax, eax
call __gnu_cxx::__to_xstring(int (*)(char*, unsigned long, char
const*, __va_list_tag*), unsigned long, char const*, ...)
mov rax, rbx
pop rbx
ret
There was a post on the libstdc++ mailing list about this some time ago. They
recommended better optimization of the vsnprintf builtin:
<a href="https://gcc.gnu.org/ml/libstdc++/2015-01/msg00007.html">https://gcc.gnu.org/ml/libstdc++/2015-01/msg00007.html</a>
When using the specialized to_string implementation from VisualC's STL gcc and
clang are perfectly able to figure out the string constant.</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>