[clang] Assertion `Owner && "definition of hidden declaration is not in a module"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/36zWW834z
```cpp
template struct S {
enum E : int;
};
template
enum S::E : int {
e, ; typename R, foo = S::E::e;
};
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaLookup.cpp:5707: void clang::Sema::diagnoseMissingImport(clang::SourceLocation, const clang::NamedDecl*, clang::Sema::MissingImportKind, bool): Assertion `Owner && "definition of hidden declaration is not in a module"' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20
1. :7:37: current parser token 'e'
#0 0x000000000442edd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442edd8)
#1 0x000000000442bc84 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442bc84)
#2 0x000000000442c2bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442c2bc)
#3 0x000000000436b338 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007111a1c45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007111a1c9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007111a1c4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007111a1c288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007111a1c2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007111a1c3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000074b336f clang::Sema::diagnoseMissingImport(clang::SourceLocation, clang::NamedDecl const*, clang::Sema::MissingImportKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74b336f)
#11 0x0000000006f7edcc clang::Sema::RequireCompleteEnumDecl(clang::EnumDecl*, clang::SourceLocation, clang::CXXScopeSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f7edcc)
#12 0x0000000006f80448 clang::Sema::RequireCompleteDeclContext(clang::CXXScopeSpec&, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f80448)
#13 0x0000000007182acb clang::Sema::getTypeName(clang::IdentifierInfo const&, clang::SourceLocation, clang::Scope*, clang::CXXScopeSpec*, bool, bool, clang::OpaquePtr, bool, bool, bool, clang::ImplicitTypenameContext, clang::IdentifierInfo**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7182acb)
#14 0x0000000006d4ed2c clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(clang::CXXScopeSpec&, bool, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d4ed2c)
#15 0x0000000006d4f2f1 clang::Parser::TryAnnotateTypeOrScopeToken(clang::ImplicitTypenameContext, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d4f2f1)
#16 0x0000000006dc6c7a clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc6c7a)
#17 0x0000000006dd3dfe clang::Parser::ParseConstantExpressionInExprEvalContext(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dd3dfe)
#18 0x0000000006d8ae6d clang::Parser::ParseEnumBody(clang::SourceLocation, clang::Decl*, clang::SkipBodyInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8ae6d)
#19 0x0000000006d8c713 clang::Parser::ParseEnumSpecifier(clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8c713)
#20 0x0000000006d8f7a7 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8f7a7)
#21 0x0000000006e65609 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e65609)
#22 0x0000000006e71cd3 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#23 0x0000000006e720ca clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e720ca)
#24 0x0000000006da2660 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da2660)
#25 0x0000000006d59100 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d59100)
#26 0x0000000006d5a035 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d5a035)
#27 0x0000000006d36faa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d36faa)
#28 0x0000000004f22898 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f22898)
#29 0x000000000524f388 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x524f388)
#30 0x00000000051dc59d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51dc59d)
#31 0x0000000005324c5d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5324c5d)
#32 0x0000000000dadaec cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdadaec)
#33 0x0000000000da470a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#34 0x0000000000da488d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#35 0x0000000004f9b379 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x000000000436b774 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436b774)
#37 0x0000000004f9bee5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x0000000004f53db2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f53db2)
#39 0x0000000004f58717 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f58717)
#40 0x0000000004f62c85 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f62c85)
#41 0x0000000000da9fea clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda9fea)
#42 0x0000000000cc5c8a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc5c8a)
#43 0x00007111a1c2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#44 0x00007111a1c2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#45 0x0000000000da40b5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda40b5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Run the C++20 reproducer from the issue, first confirming the assertion in clang::Sema::diagnoseMissingImport at clang/lib/Sema/SemaLookup.cpp:5707. Trace the call through RequireCompleteEnumDecl and RequireCompleteDeclContext. Done means the reproducer no longer aborts with the assertion and the behavior is covered by an appropriate regression test.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100