boostorg / boostorg/container

default_init results in a memset with GCC16

Open
#333 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
127
Forks
126
Avg merge
18h 53m
Merged PRs (30d)
1

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.

```cpp
boost::container::small_vector bar(100, boost::container::default_init);

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

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

```asm
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):
```asm
lea eax, [ebp-440]
push 412 ; count
push 0 ; ch
push eax ; dest
call "memset"
```

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

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.