Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

std::to_string with constant input not optimized to string constant #31342

Copy link
Copy link
Closed as not planned
@Trass3r

Description

@Trass3r
Issue body actions
Bugzilla Link 31994
Version trunk
OS Linux

Extended Description

#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:
https://gcc.gnu.org/ml/libstdc++/2015-01/msg00007.html

When using the specialized to_string implementation from VisualC's STL gcc and clang are perfectly able to figure out the string constant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaIssues migrated from bugzillainvalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibstdc++GNU libstdc++ C++ standard libraryGNU libstdc++ C++ standard library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.