default_init results in a memset with GCC16

Open
#333 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Quiet
Tech stack
cpp
Domain
compilers

Research direction

Start with the small_vector constructor using boost::container::default_init and reproduce the assembly shown with GCC16.0.1, GCC15.2, and Clang 22.1 under -std=c++26 -O3. Compare the generated code and trace whether the memset comes from the container implementation or the compiler; done means identifying the cause and documenting a fix, workaround, or confirmed compiler issue.

Written by the indexing model from the issue text.

Description

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. :)

Dominant language
C++
Stars
127
Forks
126
Avg merge
18h 53m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/container

All issues in boostorg/container

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.