crash in clang++-21 compilation when using -fkeep-static-consts
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
update: It seems that it wasn't adding these 2 options, but in fact adding -fkeep-static-consts that causes the crash.
update: more minimal reproduction code https://godbolt.org/z/K5Yb8xrxe
Adding either or both of these options to my compile command causes a crash: -fno-omit-frame-pointer -fno-optimize-sibling-calls.
In this case a trace when adding them both:
```
Stack dump:
0. Program arguments: clang++-21 -Werror -Weverything -Wconversion -Wsign-conversion -Wbool-conversion -Wdouble-promotion -Wfloat-conversion -Wstring-conversion -fsafe-buffer-usage-suggestions -Wno-reserved-identifier -Wnullability-completeness -Wno-c++98-compat -Wno-c++98-compat-pedantic -gfull -O0 -fstandalone-debug -gcolumn-info -fno-limit-debug-info -fkeep-static-consts -fno-delete-null-pointer-checks -fno-strict-aliasing -fno-inline -fno-inline-functions -fno-omit-frame-pointer -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_ASSERTIONS -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -fsanitize=alignment -fsanitize=bool -fsanitize=builtin -fsanitize=bounds -fsanitize=enum -fsanitize=float-divide-by-zero -fsanitize=function -fsanitize=implicit-unsigned-integer-truncation -fsanitize=implicit-signed-integer-truncation -fsanitize=implicit-integer-sign-change -fsanitize=integer-divide-by-zero -fsanitize=implicit-bitfield-conversion -fsanitize=nonnull-attribute -fsanitize=null -fsanitize=nullability-arg -fsanitize=nullability-assign -fsanitize=nullability-return -fsanitize=returns-nonnull-attribute -fsanitize=pointer-overflow -fsanitize=unreachable -fsanitize=return -fsanitize=shift -fsanitize=unsigned-shift-base -fsanitize=signed-integer-overflow -fsanitize=vla-bound -fsanitize=vptr -isystem /home/itaj/cncrdata/libr/boost_1_90_0 -std=c++23 -nostdinc++ -isystem /lib/llvm-21/include/c++/v1 -c result.bsheri_api/cpp_train/test_x1.exec.cld_user.cpp -o temp_generated_content.bsheri_gen/cpp_train/test_x1.exec.cld_user.o
1. parser at end of file
2. Per-file LLVM IR generation
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 libLLVM.so.21.1 0x000079b4448fc91f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 63
1 libLLVM.so.21.1 0x000079b4448fa1c7 llvm::sys::RunSignalHandlers() + 135
2 libLLVM.so.21.1 0x000079b444833e87
3 libc.so.6 0x000079b43fc45330
4 libLLVM.so.21.1 0x000079b44498b32e llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(llvm::Constant*, llvm::Type*) + 14
5 libclang-cpp.so.21.1 0x000079b44b31f212
6 libclang-cpp.so.21.1 0x000079b44b312020 clang::CodeGen::CodeGenModule::Release() + 3424
7 libclang-cpp.so.21.1 0x000079b44b3c94a2
8 libclang-cpp.so.21.1 0x000079b44b2f4806 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 166
9 libclang-cpp.so.21.1 0x000079b449e882c9 clang::ParseAST(clang::Sema&, bool, bool) + 617
10 libclang-cpp.so.21.1 0x000079b44ba876d2 clang::FrontendAction::Execute() + 50
11 libclang-cpp.so.21.1 0x000079b44b9fe134 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 948
12 libclang-cpp.so.21.1 0x000079b44bb0f37c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 700
13 clang++-21 0x000056c52027e31b cc1_main(llvm::ArrayRef, char const*, void*) + 5995
14 clang++-21 0x000056c52027b024
15 libclang-cpp.so.21.1 0x000079b44b6c2172
16 libLLVM.so.21.1 0x000079b444833b07 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) + 151
17 libclang-cpp.so.21.1 0x000079b44b6c19c6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const + 406
18 libclang-cpp.so.21.1 0x000079b44b684f02 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 546
19 libclang-cpp.so.21.1 0x000079b44b6850ef clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const + 159
20 libclang-cpp.so.21.1 0x000079b44b6a3866 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) + 406
21 clang++-21 0x000056c52027aaf9 clang_main(int, char**, llvm::ToolContext const&) + 6297
22 clang++-21 0x000056c520288ef3 main + 131
23 libc.so.6 0x000079b43fc2a1ca
24 libc.so.6 0x000079b43fc2a28b __libc_start_main + 139
25 clang++-21 0x000056c520278d25 _start + 37
clang++-21: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 21.1.8 (++20251221032922+2078da43e25a-1~exp1~20251221153059.70)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
clang++-21: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-21: note: diagnostic msg: /tmp/test_x1-f1dae6.cpp
clang++-21: note: diagnostic msg: /tmp/test_x1-f1dae6.sh
clang++-21: note: diagnostic msg:
********************
```
[test_x1-f1dae6.sh](https://github.com/user-attachments/files/25977323/test_x1-f1dae6.sh)
[test_x1-f1dae6.cpp](https://github.com/user-attachments/files/25977324/test_x1-f1dae6.cpp)
Contributor guide
Research direction
Start by running test_x1-f1dae6.sh against the attached test_x1-f1dae6.cpp and confirm the clang++-21 crash with -fkeep-static-consts. Read the stack around clang::CodeGen::CodeGenModule::Release and llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast. Done means the minimal reproduction compiles without crashing and the regression is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100