llvm / llvm/llvm-project

[Clang] Crash in `clang::Sema::ClassifyName` when calling overloaded using declarations

Open
#174,951 1 comment 0 reactions 0 assignees View on GitHub
clang:frontend crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

***Generated by fuzzer.***
Clang trunk crashed and goes back to clang-7.0 using `-std=c++20` flag.
Compiler Explorer: https://godbolt.org/z/bjTfjrszq

## Program
```cpp
template
class X {
public:
template
void execute(int a) {}
};

class Y {
public:
void execute(int a) {}
};

template
class Exec : public X, public Y {
public:
using X
::execute;
using Y::execute;
void validate() {
execute(42);
execute(42);
}
};
```

## Stack Dump
```bash
clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl::doit(const From*) [with To = clang::TemplateDecl; From = clang::NamedDecl]: Assertion `Val && "isa<> used on a null pointer"' 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++20
1. :19:9: current parser token 'execute'
2. :14:1: parsing struct/union/class body 'Exec'
3. :18:21: parsing function body 'Exec::validate'
4. :18:21: in compound statement ('{}')
#0 0x00000000042ffb48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42ffb48)
#1 0x00000000042fcf74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42fcf74)
#2 0x000000000423fd48 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007dece6442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007dece64969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007dece6442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007dece64287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007dece642871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007dece6439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000006dcc54f decltype(auto) llvm::cast(clang::NamedDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dcc54f)
#10 0x0000000006e4e325 clang::Sema::ClassifyName(clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*&, clang::SourceLocation, clang::Token const&, clang::CorrectionCandidateCallback*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e4e325)
#11 0x0000000006a49790 clang::Parser::TryAnnotateName(clang::CorrectionCandidateCallback*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a49790)
#12 0x0000000006b47528 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b47528)
#13 0x0000000006b485a6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b485a6)
#14 0x0000000006b50eee clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b50eee)
#15 0x0000000006b5173a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5173a)
#16 0x0000000006a661b0 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a661b0)
#17 0x0000000006a65e9d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a65e9d)
#18 0x0000000006ab9ef8 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ab9ef8)
#19 0x0000000006abc950 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6abc950)
#20 0x0000000006a8f77e clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a8f77e)
#21 0x0000000006b5d631 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b5d631)
#22 0x0000000006b6ab79 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#23 0x0000000006b6af8a clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6b6af8a)
#24 0x0000000006a964d0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a964d0)
#25 0x0000000006a52f2c clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a52f2c)
#26 0x0000000006a53e15 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a53e15)
#27 0x0000000006a34e9a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a34e9a)
#28 0x0000000004c657e8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c657e8)
#29 0x0000000004f5db65 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5db65)
#30 0x0000000004eddc6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eddc6e)
#31 0x000000000505829d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x505829d)
#32 0x0000000000de87de cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde87de)
#33 0x0000000000ddf1aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#34 0x0000000000ddf32d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#35 0x0000000004cd84e9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x00000000042401e4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42401e4)
#37 0x0000000004cd8aff clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x0000000004c99492 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c99492)
#39 0x0000000004c9a43e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c9a43e)
#40 0x0000000004ca1895 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca1895)
#41 0x0000000000de4b51 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde4b51)
#42 0x0000000000c8e8a4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8e8a4)
#43 0x00007dece6429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007dece6429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000ddec45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddec45)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied program with clang++ using -std=c++20 and inspect clang::Sema::ClassifyName, the entry point named in the stack trace. Trace how the overloaded using declarations are classified at the execute(42) call. Done means the reproducer no longer triggers the assertion and coverage is added for this case.

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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.