llvm / llvm/llvm-project

[clang] Assertion `isDependentContext()' failed.

Open
#207,483 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed crash-on-invalid generated by fuzzer regression:21
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer:
https://godbolt.org/z/M8KTKW6n9
```cpp
struct S;
template typename T> void foo() { S...[0] ::bar; }

template struct SS;

void baz() { foo(); }
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/CXXInheritance.cpp:116: bool clang::CXXRecordDecl::isCurrentInstantiation(const clang::DeclContext*) const: Assertion `isDependentContext()' 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++2c
1. parser at end of file
2. :2:48: instantiating function definition 'foo'
#0 0x0000000004390c08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4390c08)
#1 0x000000000438db24 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x438db24)
#2 0x000000000438e144 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x438e144)
#3 0x00000000042cc1f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000071ce31e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000071ce31e9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x000071ce31e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000071ce31e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000071ce31e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000071ce31e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000007e8267b (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e8267b)
#11 0x0000000006ea9acd getCurrentInstantiationOf(clang::QualType, clang::DeclContext*) SemaCXXScopeSpec.cpp:0:0
#12 0x0000000006ea9e9c clang::Sema::getCurrentInstantiationOf(clang::NestedNameSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea9e9c)
#13 0x0000000006eaa035 clang::Sema::computeDeclContext(clang::CXXScopeSpec const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eaa035)
#14 0x00000000073c9ebb clang::Sema::LookupParsedName(clang::LookupResult&, clang::Scope*, clang::CXXScopeSpec*, clang::QualType, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73c9ebb)
#15 0x00000000071fff20 clang::Sema::BuildQualifiedDeclarationNameExpr(clang::CXXScopeSpec&, clang::DeclarationNameInfo const&, bool, clang::TypeSourceInfo**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71fff20)
#16 0x0000000007823c24 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformDependentScopeDeclRefExpr(clang::DependentScopeDeclRefExpr*, bool, clang::TypeSourceInfo**) SemaTemplateInstantiate.cpp:0:0
#17 0x00000000077f50e8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#18 0x0000000007833727 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#19 0x0000000007833de5 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#20 0x000000000783d3a5 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x783d3a5)
#21 0x00000000078d9219 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78d9219)
#22 0x00000000078d7356 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78d7356)
#23 0x0000000006e46542 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::TUFragmentKind) (.part.0) Sema.cpp:0:0
#24 0x0000000006e46882 clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e46882)
#25 0x0000000006cac12a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6cac12a)
#26 0x0000000006c89b9a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c89b9a)
#27 0x0000000004e7f5b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e7f5b8)
#28 0x00000000051aae38 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x51aae38)
#29 0x000000000513633d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x513633d)
#30 0x00000000052ad23d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52ad23d)
#31 0x0000000000dbdc5c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbdc5c)
#32 0x0000000000db486a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#33 0x0000000000db49ed int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#34 0x0000000004ef2159 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x00000000042cc634 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42cc634)
#36 0x0000000004ef2c85 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x0000000004eae212 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eae212)
#38 0x0000000004eaf22e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eaf22e)
#39 0x0000000004ebb395 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ebb395)
#40 0x0000000000dba14a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdba14a)
#41 0x0000000000ccf42a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccf42a)
#42 0x000071ce31e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#43 0x000071ce31e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#44 0x0000000000db4215 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb4215)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the linked C++ reproducer with Clang and follow the stack from SemaCXXScopeSpec.cpp and SemaTemplateInstantiate.cpp to the assertion in CXXInheritance.cpp:116. Trace how the dependent scope is handled during foo instantiation. Done means the reproducer no longer aborts on the isDependentContext() assertion and produces the appropriate compiler result.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.