clang-22: ICE with C++20 modules when -fmodules end up in path
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I think the right thing to do here is likely to indicate to the user an error when combining -fmodules with C++20 modules.
Most of the time I get a normal compiler error, but I got a few times an ICE.
clang-22 on up-to-date archlinux:
```bash
$ git clone https://github.com/celtera/libremidi
$ cmake -S libremidi -DLIBREMIDI_MODULE_BUILD=1 -B build-modules -GNinja -DLIBREMIDI_EXAMPLES=1 -DCMAKE_CXX_COMPILER=clang++ -DLIBREMIDI_LIBRARY_MODE=MODULE -DCMAKE_CXX_FLAGS="-std=c++2c -fmodules
$ cmake --build build-modules
```
```
[1/2] Building CXX object CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o
FAILED: [code=1] CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o
/usr/bin/clang++ -DLIBREMIDI_ALSA -DLIBREMIDI_HAS_UDEV -DLIBREMIDI_JACK -DLIBREMIDI_KEYBOARD -DLIBREMIDI_PIPEWIRE -DLIBREMIDI_PIPEWIRE_UMP -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/include -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules/_deps/rwq-src -isystem /usr/include/pipewire-0.3 -isystem /usr/include/spa-0.2 -std=c++2c -fmodules -std=c++20 -fPIE -Wno-gnu-statement-expression-from-macro-expansion -Wno-c99-extensions -MD -MT CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -MF CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.d @CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.modmap -o CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -c /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/examples/modules.cpp
In file included from /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/examples/modules.cpp:3:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/cstdlib:83:
In file included from /usr/include/stdlib.h:32:
/usr/lib/clang/22/include/stddef.h:93:2: fatal error: module '_Builtin_stddef' is defined in both '/home/jcelerier/.cache/clang/ModuleCache/QPRNPORCILVL/_Builtin_stddef-1KJOD4FYBRYL9.pcm' and '/home/jcelerier/.cache/clang/ModuleCache/1X8BNGYWRVL3K/_Builtin_stddef-1KJOD4FYBRYL9.pcm'
93 | #include <__stddef_size_t.h>
| ^
1 error generated.
```
and
```
FAILED: [code=1] CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o
/usr/bin/clang++ -DLIBREMIDI_ALSA -DLIBREMIDI_HAS_UDEV -DLIBREMIDI_JACK -DLIBREMIDI_KEYBOARD -DLIBREMIDI_PIPEWIRE -DLIBREMIDI_PIPEWIRE_UMP -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/include -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules/_deps/rwq-src -isystem /usr/include/pipewire-0.3 -isystem /usr/include/spa-0.2 -std=c++2c -fmodules -std=c++20 -fPIE -Wno-gnu-statement-expression-from-macro-expansion -Wno-c99-extensions -MD -MT CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -MF CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.d @CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.modmap -o CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -c /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/examples/modules.cpp
In file included from /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/examples/modules.cpp:3:
In file included from /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/cstdlib:83:
In file included from /usr/include/stdlib.h:32:
/usr/lib/clang/22/include/stddef.h:93:2: fatal error: module '_Builtin_stddef' is defined in both '/home/jcelerier/.cache/clang/ModuleCache/QPRNPORCILVL/_Builtin_stddef-1KJOD4FYBRYL9.pcm' and '/home/jcelerier/.cache/clang/ModuleCache/1X8BNGYWRVL3K/_Builtin_stddef-1KJOD4FYBRYL9.pcm'
93 | #include <__stddef_size_t.h>
| ^
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/bin/clang++ -DLIBREMIDI_ALSA -DLIBREMIDI_HAS_UDEV -DLIBREMIDI_JACK -DLIBREMIDI_KEYBOARD -DLIBREMIDI_PIPEWIRE -DLIBREMIDI_PIPEWIRE_UMP -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/include -I/home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/build-modules/_deps/rwq-src -isystem /usr/include/pipewire-0.3 -isystem /usr/include/spa-0.2 -std=c++2c -fmodules -std=c++20 -fPIE -Wno-gnu-statement-expression-from-macro-expansion -Wno-c99-extensions -MD -MT CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -MF CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.d @CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o.modmap -o CMakeFiles/libremidi_modules.dir/examples/modules.cpp.o -c /home/jcelerier/ossia/score/3rdparty/libossia/3rdparty/libremidi/examples/modules.cpp
1. /usr/lib/clang/22/include/stddef.h:103:2: current parser token 'include'
2. /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.2.1/../../../../include/c++/15.2.1/x86_64-pc-linux-gnu/bits/c++config.h:617:1: parsing namespace 'std'
#0 0x00007fc86cb6bf9a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM.so.22.1+0x836bf9a)
#1 0x00007fc86cb6bd2b llvm::sys::CleanupOnSignal(unsigned long) (/usr/lib/libLLVM.so.22.1+0x836bd2b)
#2 0x00007fc86cb23030 (/usr/lib/libLLVM.so.22.1+0x8323030)
#3 0x00007fc86cb2324d (/usr/lib/libLLVM.so.22.1+0x832324d)
#4 0x00007fc86403e2d0 (/usr/lib/libc.so.6+0x3e2d0)
#5 0x00007fc86ef29a5f clang::ModuleMap::addHeader(clang::Module*, clang::Module::Header, clang::ModuleMap::ModuleHeaderRole, bool) (/usr/lib/libclang-cpp.so.22.1+0x1729a5f)
#6 0x00007fc86ec48fd8 clang::serialization::reader::HeaderFileInfoTrait::ReadData(clang::serialization::reader::HeaderFileInfoTrait::internal_key_type const&, unsigned char const*, unsigned int) (/usr/lib/libclang-cpp.so.22.1+0x1448fd8)
#7 0x00007fc86ec48b80 (/usr/lib/libclang-cpp.so.22.1+0x1448b80)
#8 0x00007fc86ed8e073 clang::serialization::ModuleManager::visit(llvm::function_ref, llvm::SmallPtrSetImpl*) (/usr/lib/libclang-cpp.so.22.1+0x158e073)
#9 0x00007fc86ed8dbff non-virtual thunk to clang::ASTReader::GetHeaderFileInfo(clang::FileEntryRef) (/usr/lib/libclang-cpp.so.22.1+0x158dbff)
#10 0x00007fc86ef21d20 clang::HeaderSearch::getExistingFileInfo(clang::FileEntryRef) const (/usr/lib/libclang-cpp.so.22.1+0x1721d20)
#11 0x00007fc86ef27ba6 (/usr/lib/libclang-cpp.so.22.1+0x1727ba6)
#12 0x00007fc86ef27968 clang::HeaderSearch::getFileAndSuggestModule(llvm::StringRef, clang::SourceLocation, clang::DirectoryEntry const*, bool, clang::Module*, clang::ModuleMap::KnownHeader*, bool, bool) (/usr/lib/libclang-cpp.so.22.1+0x1727968)
#13 0x00007fc86ef24da4 clang::DirectoryLookup::LookupFile(llvm::StringRef&, clang::HeaderSearch&, clang::SourceLocation, llvm::SmallVectorImpl*, llvm::SmallVectorImpl*, clang::Module*, clang::ModuleMap::KnownHeader*, bool&, bool&, bool&, llvm::SmallVectorImpl&, bool) const (/usr/lib/libclang-cpp.so.22.1+0x1724da4)
#14 0x00007fc86ef23963 clang::HeaderSearch::LookupFile(llvm::StringRef, clang::SourceLocation, bool, clang::detail::SearchDirIteratorImpl, clang::detail::SearchDirIteratorImpl*, llvm::ArrayRef, clang::DirectoryEntryRef>>, llvm::SmallVectorImpl*, llvm::SmallVectorImpl*, clang::Module*, clang::ModuleMap::KnownHeader*, bool*, bool*, bool, bool, bool, bool) (/usr/lib/libclang-cpp.so.22.1+0x1723963)
#15 0x00007fc86ef2597b clang::Preprocessor::LookupFile(clang::SourceLocation, llvm::StringRef, bool, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*, clang::detail::SearchDirIteratorImpl*, llvm::SmallVectorImpl*, llvm::SmallVectorImpl*, clang::ModuleMap::KnownHeader*, bool*, bool*, bool, bool, bool) (/usr/lib/libclang-cpp.so.22.1+0x172597b)
#16 0x00007fc86ef261ed clang::Preprocessor::LookupHeaderIncludeOrImport(clang::detail::SearchDirIteratorImpl*, llvm::StringRef&, clang::SourceLocation, clang::CharSourceRange, clang::Token const&, bool&, bool, bool&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*, llvm::StringRef&, llvm::SmallVectorImpl&, llvm::SmallVectorImpl&, clang::ModuleMap::KnownHeader&, bool) (/usr/lib/libclang-cpp.so.22.1+0x17261ed)
#17 0x00007fc86ef1ffa6 clang::Preprocessor::HandleHeaderIncludeOrImport(clang::SourceLocation, clang::Token&, clang::Token&, clang::SourceLocation, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/usr/lib/libclang-cpp.so.22.1+0x171ffa6)
#18 0x00007fc86ef1f71a clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/usr/lib/libclang-cpp.so.22.1+0x171f71a)
#19 0x00007fc86e77afc4 clang::Preprocessor::HandleDirective(clang::Token&) (/usr/lib/libclang-cpp.so.22.1+0xf7afc4)
#20 0x00007fc86e761172 clang::Lexer::Lex(clang::Token&) (/usr/lib/libclang-cpp.so.22.1+0xf61172)
#21 0x00007fc86f1651d8 (/usr/lib/libclang-cpp.so.22.1+0x19651d8)
#22 0x00007fc86ea60b15 (/usr/lib/libclang-cpp.so.22.1+0x1260b15)
#23 0x00007fc86f2a2e45 clang::Parser::ParseInnerNamespace(llvm::SmallVector const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/usr/lib/libclang-cpp.so.22.1+0x1aa2e45)
#24 0x00007fc86f2a21f7 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/usr/lib/libclang-cpp.so.22.1+0x1aa21f7)
#25 0x00007fc86ec10975 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/usr/lib/libclang-cpp.so.22.1+0x1410975)
#26 0x00007fc86eb00e98 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/lib/libclang-cpp.so.22.1+0x1300e98)
#27 0x00007fc86eafd2ef clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.22.1+0x12fd2ef)
#28 0x00007fc86ec77b8e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.22.1+0x1477b8e)
#29 0x00007fc86ec7731a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/libclang-cpp.so.22.1+0x147731a)
#30 0x0000557bf8c61320 cc1_main(llvm::ArrayRef, char const*, void*) (/usr/bin/clang+++0x11320)
#31 0x0000557bf8c60719 (/usr/bin/clang+++0x10719)
#32 0x0000557bf8c605f6 (/usr/bin/clang+++0x105f6)
#33 0x00007fc87036e18d (/usr/lib/libclang-cpp.so.22.1+0x2b6e18d)
#34 0x00007fc86cb22fca llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/usr/lib/libLLVM.so.22.1+0x8322fca)
#35 0x00007fc86ef81852 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (/usr/lib/libclang-cpp.so.22.1+0x1781852)
#36 0x00007fc86ee8610f clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/libclang-cpp.so.22.1+0x168610f)
#37 0x00007fc86ee85aa2 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/usr/lib/libclang-cpp.so.22.1+0x1685aa2)
#38 0x0000557bf8c5f187 clang_main(int, char**, llvm::ToolContext const&) (/usr/bin/clang+++0xf187)
#39 0x0000557bf8c5e5bb main (/usr/bin/clang+++0xe5bb)
#40 0x00007fc8640276c1 __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:83:3
#41 0x00007fc8640277f9 call_init /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:128:20
#42 0x00007fc8640277f9 __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:347:5
#43 0x0000557bf8c64275 _start (/usr/bin/clang+++0x14275)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 22.1.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/modules-a4f1ab.cpp
clang++: note: diagnostic msg: /tmp/modules-a4f1ab.cache
clang++: note: diagnostic msg: /tmp/modules-a4f1ab.sh
clang++: note: diagnostic msg:
********************
```
Preprocessed source:
[modules-a4f1ab.zip](https://github.com/user-attachments/files/26144454/modules-a4f1ab.zip)
Contributor guide
Research direction
Start by reproducing the failure with the CMake and clang++ command shown in the issue, including both -std=c++2c and -fmodules. No source file or test is named, so trace how clang handles this option combination. Done means it emits a normal diagnostic instead of an ICE, with a regression test covering the reproducer.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100