Issue 129021
Summary clang++-21 crashed when using precompiled header
Labels clang
Assignees
Reporter sweihub
    Hi

I have a cmake setup with precompiled headers
```cmake
# add the pch custom target as a dependency
add_dependencies(demo pch)

# add the flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include-pch ${CMAKE_CURRENT_BINARY_DIR}/stdinc.h.pch")

# target
add_custom_target(pch COMMAND ${CMAKE_CXX_COMPILER} -std=c++26 -x c++-header ${CMAKE_CURRENT_SOURCE_DIR}/include/coin/stdinc.h -o ${CMAKE_CURRENT_BINARY_DIR}/stdinc.h.pch)
```

clang++-21 crashed when compiling

```log
➜  coin git:(develop) ✗ b
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /root/quant/algo/coin/build
[2/4] Building CXX object CMakeFiles/demo.dir/src/binance.cppm.o
FAILED: CMakeFiles/demo.dir/src/binance.cppm.o CMakeFiles/demo.dir/binance.pcm
/usr/bin/clang++-21  -I/root/quant/algo/coin/include -include-pch /root/quant/algo/coin/build/stdinc.h.pch -g -std=c++26 -MD -MT CMakeFiles/demo.dir/src/binance.cppm.o -MF CMakeFiles/demo.dir/src/binance.cppm.o.d @CMakeFiles/demo.dir/src/binance.cppm.o.modmap -o CMakeFiles/demo.dir/src/binance.cppm.o -c /root/quant/algo/coin/src/binance.cppm
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /usr/lib/llvm-21/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name binance.cppm -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/root/quant/algo/coin/build -fcoverage-compilation-dir=/root/quant/algo/coin/build -resource-dir /usr/lib/llvm-21/lib/clang/21 -std=c++26 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=websocket=CMakeFiles/demo.dir/websocket.pcm -fmodule-file=json=CMakeFiles/demo.dir/json.pcm -fmodule-file=web=CMakeFiles/demo.dir/web.pcm -fmodule-file=semaphore=CMakeFiles/demo.dir/semaphore.pcm -fmodule-file=ws=CMakeFiles/demo.dir/ws.pcm -fmodule-file=wss=CMakeFiles/demo.dir/wss.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/demo.dir/src/binance.cppm.o -x pcm CMakeFiles/demo.dir/binance.pcm
 #0 0x00007f53018cbfef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-21/bin/../lib/libLLVM.so.21.0+0x102efef)
 #1 0x00007f53018c9cf9 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-21/bin/../lib/libLLVM.so.21.0+0x102ccf9)
 #2 0x00007f53018cc70d (/usr/lib/llvm-21/bin/../lib/libLLVM.so.21.0+0x102f70d)
 #3 0x00007f5300330330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x00007f530b73506a clang::ASTReader::getLocalModuleFile(clang::serialization::ModuleFile&, unsigned int) const (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x253406a)
 #5 0x00007f530b7bbebb (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x25baebb)
 #6 0x00007f530b7ba2c9 clang::ASTReader::loadDeclUpdateRecords(clang::ASTReader::PendingUpdateRecord&) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x25b92c9)
 #7 0x00007f530b769056 clang::ASTReader::finishPendingActions() (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x2568056)
 #8 0x00007f530b76c91b clang::ASTReader::FinishedDeserializing() (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x256b91b)
 #9 0x00007f530b75050a clang::ASTReader::ReadAST(llvm::StringRef, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, clang::serialization::ModuleFile**) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x254f50a)
#10 0x00007f530b8b1b22 clang::ASTUnit::LoadFromASTFile(llvm::StringRef, clang::PCHContainerReader const&, clang::ASTUnit::WhatToLoad, llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, clang::FileSystemOptions const&, std::shared_ptr<clang::HeaderSearchOptions>, std::shared_ptr<clang::LangOptions>, bool, clang::CaptureDiagsKind, bool, bool, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x26b0b22)
#11 0x00007f530b94dedd clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x274cedd)
#12 0x00007f530b8cafd5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x26c9fd5)
#13 0x00007f530b9d522c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.0+0x27d422c)
#14 0x00005583f62bd72f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-21/bin/clang+0x1372f)
#15 0x00005583f62ba5b4 (/usr/lib/llvm-21/bin/clang+0x105b4)
#16 0x00005583f62b99e2 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-21/bin/clang+0xf9e2)
#17 0x00005583f62c6f23 main (/usr/lib/llvm-21/bin/clang+0x1cf23)
#18 0x00007f53003151ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#19 0x00007f530031528b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#20 0x00005583f62b8415 _start (/usr/lib/llvm-21/bin/clang+0xe415)
clang++-21: error: unable to execute command: Segmentation fault (core dumped)
clang++-21: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 21.0.0 (++20250224081945+0770afb88ec1-1~exp1~20250224082103.749)
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/binance-cb89ea.cppm
clang++-21: note: diagnostic msg: /tmp/binance-cb89ea.sh
clang++-21: note: diagnostic msg:

********************
ninja: build stopped: subcommand failed.
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to