llvm / llvm/llvm-project

[clang] Segmentation fault when initializing const std::string

Open
#164,536 6 comments 0 reactions 0 assignees View on GitHub
clang:frontend diverges-from:gcc libstdc++
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

**system:**
`ArchLinux`

**clang version:**
```
clang version 21.1.4
Target: x86_64-pc-linux-gnu
```

**gcc version:**
`15.2.1 20250813 (GCC) `

**description:**
`After compiling and running with clang, a segmentation fault occurred, but it ran normally after compiling with gcc. I found the cause after debugging with gdb. I have provided the source code for testing and hope to get some help.`

**gcc**
```
./build/test
p=en-US
skkk: ~DesktopPlatform
```

**clang**
```
./build/test
Segmentation fault (core dumped) ./build/test
```

`gdb:`
```
(gdb) where
#0 0x0000000000405cd0 in std::char_traits::assign (__c1=@0x4f8b40: 0 '\000',
__c2=)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/char_traits.h:352
#1 0x0000000000405ae8 in std::__cxx11::basic_string, std::allocator >::_S_copy (__d=0x4f8b40 "", __s=0x0, __n=1)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.h:451
#2 0x0000000000405910 in std::__cxx11::basic_string, std::allocator >::_M_construct (this=0x4f8b30 , __str=0x0,
__n=0)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.tcc:298
#3 0x000000000040571c in std::__cxx11::basic_string, std::allocator >::basic_string (this=0x4f8b30 , __str=...)
at /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/bits/basic_string.h:617
#4 0x0000000000405145 in __cxx_global_var_init.1(void) ()
at test/platform.hpp:18
```

**test sources:**

[test.zip](https://github.com/user-attachments/files/23044910/test.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.