Skip to content

default_init results in a memset with GCC16 #333

@Chaosvex

Description

@Chaosvex

It's perhaps a little early to open an issue for this but since I'm already toying with GCC16, I was surprised to see that it now generates a memset to zero init even when default_init is used.

    boost::container::small_vector<float, 100> bar(100, boost::container::default_init);

    for(auto b : bar)
        std::cout << b;

GCC16.0.1 (-std=c++26 -O3):

        push    r12
        mov     edx, 424
        xor     esi, esi
        push    rbp
        push    rbx
        sub     rsp, 432
        mov     rdi, rsp
        lea     r12, [rsp+24]
        lea     rbp, [rsp+424]
        call    "memset" ; zero init 400 bytes
        mov     eax, 100
        mov     QWORD PTR [rsp], r12
        mov     rbx, r12
        movq    xmm0, rax
        punpcklqdq      xmm0, xmm0
        movups  XMMWORD PTR [rsp+8], xmm0

32-bit (only the relevant bit):

        lea     eax, [ebp-440]
        push    412 ; count
        push    0 ; ch
        push    eax ; dest
        call    "memset"

GCC15.2 (-std=c++26 -O3):

        push    r12
        mov     eax, 100
        push    rbp
        movq    xmm0, rax
        push    rbx
        punpcklqdq      xmm0, xmm0
        sub     rsp, 432
        lea     r12, [rsp+24]
        movups  XMMWORD PTR [rsp+8], xmm0
        lea     rbp, [rsp+424]
        mov     QWORD PTR [rsp], r12
        mov     rbx, r12

Clang 22.1 (-std=c++26 -O3):

        push    r15
        push    r14
        push    rbx
        sub     rsp, 432
        lea     r14, [rsp + 32]
        mov     qword ptr [rsp + 24], 100
        mov     qword ptr [rsp + 8], r14
        mov     qword ptr [rsp + 16], 100
        mov     r15d, 24
        mov     rbx, qword ptr [rip + std::cout@GOTPCREL]

I'm not yet sure if this is a compiler regression, an issue with the containers, a skill issue or something else. Again, happy to close it if it's too soon. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions