`clang` crash with stack trace (possibly C++20 module related)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I was greeted with this stack trace after running my in-development project with some changes; in particular, the file `clang` was processing when the crash happened (`format.cppm`) is new to the project.
This project is built using `cmake`, `ninja`, `clang-22`, and `libstdc++-16`. Most of the code lives in C++20 modules. I wouldn't be surprised if the crash is somehow related to the C++20 module implementation in `clang`.
Stack dump:
```
0. Program arguments: /usr/bin/clang++-22 -I/home/devin/projects/synthclone/out/build/include -isystem /home/devin/projects/synthclone/out/modules/synthclone.util/module-synthclone.util-shared_autogen/include --stdlib=libstdc++ -Wno-reserved-module-identifier -Wno-unused-command-line-argument -g -std=c++23 -fPIC -fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc -Werror -MD -MT modules/synthclone.util/CMakeFiles/module-synthclone.util-shared.dir/src/format.cppm.o -MF modules/synthclone.util/CMakeFiles/module-synthclone.util-shared.dir/src/format.cppm.o.d @modules/synthclone.util/CMakeFiles/module-synthclone.util-shared.dir/src/format.cppm.o.modmap -o modules/synthclone.util/CMakeFiles/module-synthclone.util-shared.dir/src/format.cppm.o -c /home/devin/projects/synthclone/modules/synthclone.util/src/format.cppm
1. parser at end of file
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.22.1 0x00007306b89a0a9f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 63
1 libLLVM.so.22.1 0x00007306b899e317 llvm::sys::RunSignalHandlers() + 135
2 libLLVM.so.22.1 0x00007306b88cc057
3 libc.so.6 0x00007306b3445cb0
4 libclang-cpp.so.22.1 0x00007306befc0784
5 libclang-cpp.so.22.1 0x00007306befbfe07
6 libclang-cpp.so.22.1 0x00007306befbfd4c
7 libclang-cpp.so.22.1 0x00007306befbfd4c
8 libclang-cpp.so.22.1 0x00007306befbfb48 clang::Sema::checkExposure(clang::TranslationUnitDecl const*) + 168
9 libclang-cpp.so.22.1 0x00007306bebc497b clang::Sema::ActOnEndOfTranslationUnit() + 8779
10 libclang-cpp.so.22.1 0x00007306be1ef8fd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) + 429
11 libclang-cpp.so.22.1 0x00007306be12d9ae clang::ParseAST(clang::Sema&, bool, bool) + 782
12 libclang-cpp.so.22.1 0x00007306bfe78d42 clang::FrontendAction::Execute() + 50
13 libclang-cpp.so.22.1 0x00007306bfdedc74 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 948
14 libclang-cpp.so.22.1 0x00007306bff067aa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 746
15 clang++-22 0x000062017eb107ba cc1_main(llvm::ArrayRef, char const*, void*) + 6826
16 clang++-22 0x000062017eb0d19a
17 clang++-22 0x000062017eb0ec50
18 libclang-cpp.so.22.1 0x00007306bfaa3c82
19 libLLVM.so.22.1 0x00007306b88cbcd7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) + 151
20 libclang-cpp.so.22.1 0x00007306bfaa36c6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const + 406
21 libclang-cpp.so.22.1 0x00007306bfa62942 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 546
22 libclang-cpp.so.22.1 0x00007306bfa62b1f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const + 143
23 libclang-cpp.so.22.1 0x00007306bfa83e96 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) + 406
24 clang++-22 0x000062017eb0cc77 clang_main(int, char**, llvm::ToolContext const&) + 6343
25 clang++-22 0x000062017eb1af83 main + 131
26 libc.so.6 0x00007306b342a601
27 libc.so.6 0x00007306b342a718 __libc_start_main + 136
28 clang++-22 0x000062017eb0ae75 _start + 37
clang++-22: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 22.1.2 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-22/bin
clang++-22: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-22: note: diagnostic msg: /tmp/format-7e0bdc.cppm
clang++-22: note: diagnostic msg: /tmp/format-7e0bdc.sh
clang++-22: note: diagnostic msg:
********************
```
[format-7e0bdc.cppm.cpp](https://github.com/user-attachments/files/28044351/format-7e0bdc.cppm.cpp) (renamed from `format-7e0bdc.cppm` because `github` complained the file type was *unsupported*)
[format-7e0bdc.sh](https://github.com/user-attachments/files/28044325/format-7e0bdc.sh)
Contributor guide
Research direction
Start by running format-7e0bdc.sh against the attached format-7e0bdc.cppm.cpp reproducer, then inspect the stack frames in clang::Sema::checkExposure and clang::Sema::ActOnEndOfTranslationUnit. Done means clang++-22 no longer exits with signal 139 for this C++20 module input and instead compiles it or reports a diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100