[clang] Assertion `(!getLangOpts().CPlusPlusModules || SeenGMF == (bool)this->TheGlobalModuleFragment) && "mismatched global module state"` failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following code:
```cpp
module;
module :private;
export module Foo;
```
Resulted in this output:
```
:2:9: error: private module fragment declaration with no preceding module declaration
2 | module :private;
| ^
clang-24: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaModule.cpp:318: clang::Sema::DeclGroupPtrTy clang::Sema::ActOnModuleDecl(clang::SourceLocation, clang::SourceLocation, clang::Sema::ModuleDeclKind, clang::ModuleIdPath, clang::ModuleIdPath, clang::Sema::ModuleImportState&, bool): Assertion `(!getLangOpts().CPlusPlusModules || SeenGMF == (bool)this->TheGlobalModuleFragment) && "mismatched global module state"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -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=/app -fcoverage-compilation-dir=/app -resource-dir /cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/lib/clang/24 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../include/c++/17.0.0/backward -internal-isystem /cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/lib/clang/24/include -internal-isystem /cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/../include/x86_64-unknown-linux-gnu -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -fdwarf2-cfi-asm -o /tmp/example-50192a.o -x c++
1. parser at end of file
#0 0x0000000004414e58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x4414e58)
#1 0x0000000004411d04 llvm::sys::RunSignalHandlers() (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x4411d04)
#2 0x0000000004411e7e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000000004411f28 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x00007cff3b645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007cff3b69ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007cff3b64527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007cff3b6288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007cff3b62881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007cff3b63b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000074f2315 (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x74f2315)
#11 0x0000000006d67756 clang::Parser::ParseModuleDecl(clang::Sema::ModuleImportState&) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x6d67756)
#12 0x0000000006d6f786 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x6d6f786)
#13 0x0000000006d4b93a clang::ParseAST(clang::Sema&, bool, bool) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x6d4b93a)
#14 0x0000000004f21c78 clang::CodeGenAction::ExecuteAction() (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x4f21c78)
#15 0x000000000524ec78 clang::FrontendAction::Execute() (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x524ec78)
#16 0x00000000051dc4fd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x51dc4fd)
#17 0x000000000532324d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0x532324d)
#18 0x0000000000d91d0c cc1_main(llvm::ArrayRef, char const*, void*) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0xd91d0c)
#19 0x0000000000d88a0a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#20 0x0000000000d8ce1b clang_main(int, char**, llvm::ToolContext const&) (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0xd8ce1b)
#21 0x0000000000ccc14a main (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0xccc14a)
#22 0x00007cff3b62a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#23 0x00007cff3b62a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#24 0x0000000000d883b5 _start (/cefs/fc/fc84883d6260285471aa9b2c_clang-assertions-trunk-20260830/bin/clang-24+0xd883b5)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed with exit code -2 (use -v to see invocation)
```
Trunk: https://godbolt.org/z/E5M44x9ov
Goes back to clang-15: https://godbolt.org/z/8c9Pqf3Mv
*This bug was found by [fusion-fuzz](https://github.com/fusion-fuzz/fusion-fuzz)*
Contributor guide
Research direction
Reproduce the crash with the three-line C++20 input, then inspect llvm/tools/clang/lib/Sema/SemaModule.cpp around line 318 and the Parser::ParseModuleDecl path shown in the stack trace. Done means the invalid module sequence reports its diagnostic without triggering the assertion or aborting clang.
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
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100