| Issue |
176155
|
| Summary |
[Clang] Assertion `isDependentContext() && "cannot iterate dependent diagnostics of non-dependent context"` failed.
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
Xniao
|
***Generated by fuzzer.***
Clang trunk crashed and goes back to 3.4.
Compiler Explorer: https://godbolt.org/z/fGoT444x9
## Program
```cpp
template <int> struct bad {
template <class T, auto =
[] {
for (int i = 0; i < 100; ++i) {
struct LoopHelper {
static constexpr void process() {}
};
}
}>
static void f(T) {}
};
int main() { bad<0>::f(0); }
```
## Stack Dump
```bash
<source>:4:44: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified
4 | for (int i = 0; i < 100; ++i) {
| ^
<source>:3:29: note: while substituting into a lambda _expression_ here
3 | [] {
| ^
<source>:10:15: note: in instantiation of default argument for 'f<int>' required here
10 | static void f(T) {}
| ^~~~~~~
<source>:13:14: note: while substituting deduced template arguments into function template 'f' [with T = int, $1 = (no value)]
13 | int main() { bad<0>::f(0); }
| ^
<source>:4:37: note: 'i' declared here
4 | for (int i = 0; i < 100; ++i) {
| ^
<source>:3:26: note: lambda _expression_ begins here
3 | [] {
| ^
<source>:3:27: note: capture 'i' by value
3 | [] {
| ^
| i
<source>:3:27: note: capture 'i' by reference
3 | [] {
| ^
| &i
<source>:3:27: note: default capture by value
3 | [] {
| ^
| =
<source>:3:27: note: default capture by reference
3 | [] {
| ^
| &
<source>:4:55: error: variable 'i' cannot be implicitly captured in a lambda with no capture-default specified
4 | for (int i = 0; i < 100; ++i) {
| ^
<source>:4:37: note: 'i' declared here
4 | for (int i = 0; i < 100; ++i) {
| ^
<source>:3:26: note: lambda _expression_ begins here
3 | [] {
| ^
<source>:3:27: note: capture 'i' by value
3 | [] {
| ^
| i
<source>:3:27: note: capture 'i' by reference
3 | [] {
| ^
| &i
<source>:3:27: note: default capture by value
3 | [] {
| ^
| =
<source>:3:27: note: default capture by reference
3 | [] {
| ^
| &
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/DependentDiagnostic.h:178: clang::DeclContext::ddiag_range clang::DeclContext::ddiags() const: Assertion `isDependentContext() && "cannot iterate dependent diagnostics of non-dependent context"' 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-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++23 <source>
1. <source>:13:25: current parser token ')'
2. <source>:13:12: parsing function body 'main'
3. <source>:13:12: in compound statement ('{}')
4. <source>:6:54: instantiating function definition 'bad<0>::(lambda)::operator()()::LoopHelper::process'
#0 0x00000000043089a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43089a8)
#1 0x0000000004305e04 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4305e04)
#2 0x0000000004248118 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000747bd1442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000747bd14969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000747bd1442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000747bd14287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000747bd142871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000747bd1439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x000000000762ff20 clang::TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl(clang::NonTypeTemplateParmDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x762ff20)
#10 0x0000000007684cd2 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7684cd2)
#11 0x0000000007682846 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7682846)
#12 0x0000000007683709 clang::TemplateDeclInstantiator::VisitCXXRecordDecl(clang::CXXRecordDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7683709)
#13 0x0000000007693184 void llvm::function_ref<void ()>::callback_fn<clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&)::'lambda'()>(long) SemaTemplateInstantiateDecl.cpp:0:0
#14 0x0000000008546fc1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8546fc1)
#15 0x000000000762d47a clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x762d47a)
#16 0x0000000007597aaa clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDeclStmt(clang::DeclStmt*) SemaTemplateInstantiate.cpp:0:0
#17 0x00000000075df765 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#18 0x00000000075e6a57 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformForStmt(clang::ForStmt*) SemaTemplateInstantiate.cpp:0:0
#19 0x00000000075df765 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#20 0x00000000075a1685 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformLambdaExpr(clang::LambdaExpr*) SemaTemplateInstantiate.cpp:0:0
#21 0x00000000075a25a9 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#22 0x00000000075b9147 (anonymous namespace)::TemplateInstantiator::TransformTemplateArgument(clang::TemplateArgumentLoc const&, clang::TemplateArgumentLoc&, bool) SemaTemplateInstantiate.cpp:0:0
#23 0x00000000075b96e7 clang::Sema::SubstTemplateArgument(clang::TemplateArgumentLoc const&, clang::MultiLevelTemplateArgumentList const&, clang::TemplateArgumentLoc&, clang::SourceLocation, clang::DeclarationName const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75b96e7)
#24 0x000000000744ecb3 clang::Sema::SubstDefaultTemplateArgumentIfAvailable(clang::TemplateDecl*, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::Decl*, llvm::ArrayRef<clang::TemplateArgument>, llvm::ArrayRef<clang::TemplateArgument>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x744ecb3)
#25 0x00000000074deb37 ConvertDeducedTemplateArguments(clang::Sema&, clang::NamedDecl*, clang::TemplateParameterList*, bool, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, clang::sema::TemplateDeductionInfo&, clang::Sema::CheckTemplateArgumentInfo&, clang::LocalInstantiationScope*, unsigned int, bool*) SemaTemplateDeduction.cpp:0:0
#26 0x000000000753621d clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, bool, bool, llvm::function_ref<bool (bool)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x753621d)
#27 0x0000000007537aea void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>, bool)>)::'lambda1'()>(long) SemaTemplateDeduction.cpp:0:0
#28 0x0000000008546fc1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8546fc1)
#29 0x0000000007516510 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>, bool)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7516510)
#30 0x0000000007364cab AddTemplateOverloadCandidateImmediately(clang::Sema&, clang::OverloadCandidateSet&, clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) SemaOverload.cpp:0:0
#31 0x000000000736579f clang::OverloadCandidateSet::InjectNonDeducedTemplateCandidates(clang::Sema&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x736579f)
#32 0x0000000007365973 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7365973)
#33 0x000000000737ebab clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x737ebab)
#34 0x0000000006fdd1ba clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fdd1ba)
#35 0x0000000006fe26cc clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fe26cc)
#36 0x0000000006ae0d47 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ae0d47)
#37 0x0000000006ad9c5a clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ad9c5a)
#38 0x0000000006adbeb7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6adbeb7)
#39 0x0000000006adbf49 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6adbf49)
#40 0x0000000006ae0529 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ae0529)
#41 0x0000000006b65df9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b65df9)
#42 0x0000000006b5d2a4 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5d2a4)
#43 0x0000000006b5dc86 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5dc86)
#44 0x0000000006b665ce clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b665ce)
#45 0x0000000006b66e1a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b66e1a)
#46 0x0000000006a6d26b clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a6d26b)
#47 0x0000000006aa36dd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6aa36dd)
#48 0x0000000006a603cb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a603cb)
#49 0x0000000006a60bbf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a60bbf)
#50 0x0000000006a689ea clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a689ea)
#51 0x0000000006a69985 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a69985)
#52 0x0000000006a4aa0a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/cla<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs