[clang] Assertion `D >= 0 && "The depth cannot be negative"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/1hvzaKv4z
```cpp
template
concept foo = requires { L.template operator()(); };
template concept bar = foo<[]{}>;
template requires bar
constexpr unsigned baz = [] { return 42; }();
constexpr auto L = [] { return __is_same(T, long); };
static_assert(baz == 42, "");
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/DeclTemplate.h:1142: void clang::TemplateParmPosition::setDepth(int): Assertion `D >= 0 && "The depth cannot be negative"' 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. :10:22: current parser token '=='
#0 0x00000000043f9708 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f9708)
#1 0x00000000043f65c4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f65c4)
#2 0x00000000043f6bec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f6bec)
#3 0x0000000004335c28 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000703ae2045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000703ae209eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x0000703ae204527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000703ae20288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000703ae202881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000703ae203b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007f808ef (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7f808ef)
#11 0x0000000007f80cf1 clang::NonTypeTemplateParmDecl::Create(clang::ASTContext const&, clang::DeclContext*, clang::SourceLocation, clang::SourceLocation, int, int, clang::IdentifierInfo const*, clang::QualType, clang::TypeSourceInfo*, llvm::ArrayRef, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7f80cf1)
#12 0x00000000079099fe clang::TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(clang::NonTypeTemplateParmDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79099fe)
#13 0x000000000796b1d3 clang::TemplateDeclInstantiator::SubstTemplateParams(clang::TemplateParameterList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x796b1d3)
#14 0x00000000078754af clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) SemaTemplateInstantiate.cpp:0:0
#15 0x00000000078776b2 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#16 0x00000000078939ce clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformSubstNonTypeTemplateParmExpr(clang::SubstNonTypeTemplateParmExpr*) SemaTemplateInstantiate.cpp:0:0
#17 0x0000000007877533 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#18 0x000000000788edc4 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#19 0x000000000788f459 (anonymous namespace)::TemplateInstantiator::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#20 0x000000000789109c bool clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTemplateArguments(clang::TemplateArgumentLoc const*, clang::TemplateArgumentLoc const*, clang::TemplateArgumentListInfo&, bool) (.constprop.0) SemaTemplateInstantiate.cpp:0:0
#21 0x0000000007891617 clang::Sema::SubstTemplateArgumentsInParameterMapping(llvm::ArrayRef, clang::SourceLocation, clang::MultiLevelTemplateArgumentList const&, clang::TemplateArgumentListInfo&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7891617)
#22 0x0000000006ff7b9d (anonymous namespace)::ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(clang::NormalizedConstraintWithParamMapping const&, clang::MultiLevelTemplateArgumentList const&, llvm::SmallVector&) (.constprop.0) SemaConcept.cpp:0:0
#23 0x000000000705c1ca (anonymous namespace)::ConstraintSatisfactionChecker::Evaluate(clang::AtomicConstraint const&, clang::MultiLevelTemplateArgumentList const&) SemaConcept.cpp:0:0
#24 0x000000000705f640 (anonymous namespace)::ConstraintSatisfactionChecker::Evaluate(clang::ConceptIdConstraint const&, clang::MultiLevelTemplateArgumentList const&) SemaConcept.cpp:0:0
#25 0x000000000705f640 (anonymous namespace)::ConstraintSatisfactionChecker::Evaluate(clang::ConceptIdConstraint const&, clang::MultiLevelTemplateArgumentList const&) SemaConcept.cpp:0:0
#26 0x0000000007061de7 CheckConstraintSatisfaction(clang::Sema&, clang::NamedDecl const*, llvm::ArrayRef, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&, clang::Expr**, clang::ConceptReference const*) SemaConcept.cpp:0:0
#27 0x0000000007062646 clang::Sema::CheckConstraintSatisfaction(llvm::PointerUnion, llvm::ArrayRef, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&, clang::ConceptReference const*, clang::Expr**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7062646)
#28 0x0000000007063c18 clang::Sema::EnsureTemplateArgumentListConstraints(clang::TemplateDecl*, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7063c18)
#29 0x00000000077470fd clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::TemplateParameterList*, clang::SourceLocation, clang::TemplateArgumentListInfo&, clang::DefaultArguments const&, bool, clang::Sema::CheckTemplateArgumentInfo&, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77470fd)
#30 0x000000000774ea91 clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::TemplateArgumentListInfo const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x774ea91)
#31 0x000000000774ffb4 clang::Sema::CheckVarTemplateId(clang::CXXScopeSpec const&, clang::DeclarationNameInfo const&, clang::VarTemplateDecl*, clang::NamedDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x774ffb4)
#32 0x0000000007750217 clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&, clang::SourceLocation, clang::LookupResult&, bool, clang::TemplateArgumentListInfo const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7750217)
#33 0x000000000727a7b8 clang::Sema::ActOnIdExpression(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, clang::CorrectionCandidateCallback*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x727a7b8)
#34 0x0000000006da8bb5 clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da8bb5)
#35 0x0000000006da8f3e clang::Parser::ParseCXXIdExpression(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da8f3e)
#36 0x0000000006d86da4 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d86da4)
#37 0x0000000006d86680 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d86680)
#38 0x0000000006d9387e clang::Parser::ParseConstantExpressionInExprEvalContext(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9387e)
#39 0x0000000006d6a606 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d6a606)
#40 0x0000000006d61f66 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d61f66)
#41 0x0000000006d18b26 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d18b26)
#42 0x0000000006d19a15 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d19a15)
#43 0x0000000006cf692a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cf692a)
#44 0x0000000004ef7c58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ef7c58)
#45 0x00000000052234b8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52234b8)
#46 0x00000000051b0abd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51b0abd)
#47 0x00000000052fb3cd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52fb3cd)
#48 0x0000000000da6cbc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda6cbc)
#49 0x0000000000d9d8ca ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#50 0x0000000000d9da4d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#51 0x0000000004f6ef29 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#52 0x0000000004336064 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4336064)
#53 0x0000000004f6fa95 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#54 0x0000000004f28462 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f28462)
#55 0x0000000004f2cc97 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f2cc97)
#56 0x0000000004f371f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f371f5)
#57 0x0000000000da31aa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda31aa)
#58 0x0000000000cbee3a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcbee3a)
#59 0x0000703ae202a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#60 0x0000703ae202a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#61 0x0000000000d9d275 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9d275)
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.