llvm / llvm/llvm-project

[clang][module] Clang crash on assertion `Modules[Name] && Modules[Name]->Kind == Module::ModuleInterfaceUnit && "creating implementation module without an interface"'`

Open
#200,381 1 comment 0 reactions 0 assignees View on GitHub
clang:modules crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

It happens on both the assert and plain build, can be triggered on the trunk version.
Seems to be introduced since clang 17.0.0, cannot be triggered in clang 16.0.0.

https://godbolt.org/z/GWaxTYveT
```cxx
#pragma clang module build foo
module foo {}
#pragma clang module endbuild
module foo {}
```
```
-std=c++20 -fsyntax-only
```

stacktrace
```
:4:11: error: expected ';' after module name
4 | module foo {}
| ^
| ;
clang++: /root/llvm-project/clang/lib/Lex/ModuleMap.cpp:921: clang::Module* clang::ModuleMap::createModuleForImplementationUnit(clang::SourceLocation, llvm::StringRef): Assertion `Modules[Name] && Modules[Name]->Kind == Module::ModuleInterfaceUnit && "creating implementation module without an interface"' failed.
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: /opt/compiler-explorer/clang-assertions-17.0.1/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -fsyntax-only -fsyntax-only
1. :4:12: current parser token '{'
#0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558)
#1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc)
#2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007bf66f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007bf66f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007bf66f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007bf66f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007bf66f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007bf66f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000078a746d clang::ModuleMap::createModuleForImplementationUnit(clang::SourceLocation, llvm::StringRef) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x78a746d)
#10 0x00000000065987b4 clang::Sema::ActOnModuleDecl(clang::SourceLocation, clang::SourceLocation, clang::Sema::ModuleDeclKind, llvm::ArrayRef>, llvm::ArrayRef>, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x65987b4)
#11 0x0000000005df58af clang::Parser::ParseModuleDecl(clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df58af)
#12 0x0000000005df770e clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df770e)
#13 0x0000000005df78a0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df78a0)
#14 0x0000000005deb732 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb732)
#15 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09)
#16 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce)
#17 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6)
#18 0x0000000000bc67eb cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb)
#19 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0
#20 0x0000000003f83419 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#21 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4)
#22 0x0000000003f83a0f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#23 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275)
#24 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd)
#25 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d)
#26 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87)
#27 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61)
#28 0x00007bf66f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#29 0x00007bf66f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#30 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.