[clang] `UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:7202!` using `-code-completion`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This issue seems to be related to https://github.com/llvm/llvm-project/pull/96509, but this one has been merged.
on godbolt:
https://godbolt.org/z/sWMebab31
use
```
-std=c++17 -Xclang -code-completion-at -Xclang example.cpp:50:25
```
to reproduce
seems to be introduced since clang 16.0.0
```cxx
template struct A {
struct B {
template struct X {};
typedef int arg;
};
struct C {
typedef B::X x;
};
};
template <> struct A::B {
template struct X {};
static const int arg = 0;
};
A::C::x a;
```
stacktrace:
```
Unable to find instantiation of declaration!
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:7202!
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++26 -Xclang -code-completion-at -Xclang example.cpp:50:25
1. :16:3: at annotation token
2. :6:12: instantiating class definition 'A::C'
#0 0x0000000004371078 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4371078)
#1 0x000000000436deb4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436deb4)
#2 0x000000000436e4d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x436e4d4)
#3 0x00000000042aa0f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007c7d2f845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007c7d2f89eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007c7d2f84527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007c7d2f8288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00000000042b4c2a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42b4c2a)
#9 0x00000000078637bc clang::Sema::FindInstantiatedDecl(clang::SourceLocation, clang::NamedDecl*, clang::MultiLevelTemplateArgumentList const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78637bc)
#10 0x000000000779fba6 (anonymous namespace)::TemplateInstantiator::TransformDecl(clang::SourceLocation, clang::Decl*) SemaTemplateInstantiate.cpp:0:0
#11 0x000000000779b89e (anonymous namespace)::TemplateInstantiator::TransformTemplateName(clang::NestedNameSpecifierLoc&, clang::SourceLocation, clang::TemplateName, clang::SourceLocation, clang::QualType, clang::NamedDecl*, bool) SemaTemplateInstantiate.cpp:0:0
#12 0x000000000779b0e4 (anonymous namespace)::TemplateInstantiator::TransformTemplateName(clang::NestedNameSpecifierLoc&, clang::SourceLocation, clang::TemplateName, clang::SourceLocation, clang::QualType, clang::NamedDecl*, bool) SemaTemplateInstantiate.cpp:0:0
#13 0x00000000077b1029 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateSpecializationType(clang::TypeLocBuilder&, clang::TemplateSpecializationTypeLoc, clang::QualType, clang::NamedDecl*, bool) SemaTemplateInstantiate.cpp:0:0
#14 0x00000000077905d4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&, clang::TypeLoc) SemaTemplateInstantiate.cpp:0:0
#15 0x0000000007794627 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) SemaTemplateInstantiate.cpp:0:0
#16 0x00000000077989f5 clang::Sema::SubstType(clang::TypeSourceInfo*, clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation, clang::DeclarationName, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77989f5)
#17 0x000000000787486a clang::TemplateDeclInstantiator::InstantiateTypedefNameDecl(clang::TypedefNameDecl*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x787486a)
#18 0x0000000007875041 clang::TemplateDeclInstantiator::VisitTypedefDecl(clang::TypedefDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7875041)
#19 0x000000000779a043 clang::Sema::InstantiateClassImpl(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x779a043)
#20 0x000000000779accf clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x779accf)
#21 0x00000000078888af void llvm::function_ref::callback_fn(long) SemaType.cpp:0:0
#22 0x0000000008716f81 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8716f81)
#23 0x000000000789589e clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x789589e)
#24 0x0000000007895c5f clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7895c5f)
#25 0x0000000006e3fba3 clang::Sema::RequireCompleteDeclContext(clang::CXXScopeSpec&, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e3fba3)
#26 0x00000000070386db 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+++0x70386db)
#27 0x0000000006c78868 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+++0x6c78868)
#28 0x0000000006c31057 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c31057)
#29 0x0000000006c31adf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c31adf)
#30 0x0000000006c395a1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c395a1)
#31 0x0000000006c3a4b5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c3a4b5)
#32 0x0000000006c1b38a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c1b38a)
#33 0x0000000004e5f478 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e5f478)
#34 0x0000000005195578 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5195578)
#35 0x0000000005112d8d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5112d8d)
#36 0x00000000052938dd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52938dd)
#37 0x0000000000e2048b cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe2048b)
#38 0x0000000000e16cca ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#39 0x0000000000e16e4d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#40 0x0000000004ed1a19 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#41 0x00000000042aa534 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42aa534)
#42 0x0000000004ed2066 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#43 0x0000000004e8e992 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e8e992)
#44 0x0000000004e8f93e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e8f93e)
#45 0x0000000004e97b45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e97b45)
#46 0x0000000000e1c794 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe1c794)
#47 0x0000000000cc029a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc029a)
#48 0x00007c7d2f82a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#49 0x00007c7d2f82a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#50 0x0000000000e16765 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe16765)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Assessment
This issue has not been assessed yet.