[Clang][Regression:21] Crash on typo correction of overloaded member function template
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This crash was discovered when typing the name of overloaded member function template while using clangd. The code is as follows:
```c++
template
class FramedSpan {
public:
template
ElemT *ArrayData();
template
const ElemT *ArrayData() const;
const ElemT &operator[](unsigned idx) const {
return ArrayDat; // expected "did you mean 'ArrayData'?" here
}
};
```
This is a Clang 21 regression.
See https://compiler-explorer.com/z/b4vPxajqs.
Assertion:
```console
clang++: /root/llvm-project/llvm/include/llvm/ADT/SmallVector.h:297:
T& llvm::SmallVectorTemplateCommon >::operator[](llvm::SmallVectorTemplateCommon >::size_type) [with T = clang::DeducedTemplateArgument; = void; llvm::SmallVectorTemplateCommon >::reference = clang::DeducedTemplateArgument&; llvm::SmallVectorTemplateCommon >::size_type = long unsigned int]:
Assertion `idx < size()' failed.
```
Stack dump
```console
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
1. :11:24: current parser token ';'
2. :2:1: parsing struct/union/class body 'FramedSpan'
3. :10:49: parsing function body 'FramedSpan::operator[]'
4. :10:49: in compound statement ('{}')
#0 0x00000000044ee5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee5a8)
#1 0x00000000044eb3d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb3d4)
#2 0x00000000044eb9f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb9f4)
#3 0x000000000442ac98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007145f0642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007145f06969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007145f0642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007145f06287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007145f062871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007145f0639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x000000000784abf1 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#11 0x000000000784cb7d DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, clang::TemplateArgument const&, clang::TemplateArgument, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl&, bool*) SemaTemplateDeduction.cpp:0:0
#12 0x000000000784d322 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, llvm::ArrayRef, llvm::ArrayRef, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, bool, bool, PackFold, bool*) SemaTemplateDeduction.cpp:0:0
#13 0x000000000784e6b5 DeduceTemplateSpecArguments(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl&, bool*) SemaTemplateDeduction.cpp:0:0
#14 0x0000000007848137 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#15 0x00000000078542b7 clang::TemplateDeductionResult DeduceForEachType, llvm::ArrayRef, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, unsigned int, PartialOrderingKind, bool*, llvm::SmallBitVector*)::'lambda'(clang::Sema&, clang::TemplateParameterList*, int, int, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, PartialOrderingKind)>(clang::Sema&, clang::TemplateParameterList*, llvm::ArrayRef, llvm::ArrayRef, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, PartialOrderingKind, bool, DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, llvm::ArrayRef, llvm::ArrayRef, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, unsigned int, PartialOrderingKind, bool*, llvm::SmallBitVector*)::'lambda'(clang::Sema&, clang::TemplateParameterList*, int, int, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl&, PartialOrderingKind)&&) (.constprop.0) SemaTemplateDeduction.cpp:0:0
#16 0x0000000007855488 isAtLeastAsSpecializedAs(clang::Sema&, clang::SourceLocation, clang::FunctionTemplateDecl*, clang::FunctionTemplateDecl*, clang::TemplatePartialOrderingContext, llvm::ArrayRef, llvm::ArrayRef, bool) SemaTemplateDeduction.cpp:0:0
#17 0x0000000007856209 clang::Sema::getMoreSpecializedTemplate(clang::FunctionTemplateDecl*, clang::FunctionTemplateDecl*, clang::SourceLocation, clang::TemplatePartialOrderingContext, unsigned int, clang::QualType, clang::QualType, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7856209)
#18 0x00000000076a53ba clang::isBetterOverloadCandidate(clang::Sema&, clang::OverloadCandidate const&, clang::OverloadCandidate const&, clang::SourceLocation, clang::OverloadCandidateSet::CandidateSetKind, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76a53ba)
#19 0x00000000076ae6cc clang::OverloadCandidateSet::BestViableFunctionImpl(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76ae6cc)
#20 0x00000000076c8da4 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76c8da4)
#21 0x00000000072d8471 clang::Sema::DiagnoseEmptyLookup(clang::Scope*, clang::CXXScopeSpec&, clang::LookupResult&, clang::CorrectionCandidateCallback&, clang::TemplateArgumentListInfo*, llvm::ArrayRef, clang::DeclContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72d8471)
#22 0x00000000073091ec clang::Sema::ActOnIdExpression(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, clang::CorrectionCandidateCallback*, bool, clang::Token*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73091ec)
#23 0x0000000006e22a09 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e22a09)
#24 0x0000000006e23827 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e23827)
#25 0x0000000006e238b9 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e238b9)
#26 0x0000000006e27ed9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e27ed9)
#27 0x0000000006ea0f65 clang::Parser::ParseReturnStatement() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea0f65)
#28 0x0000000006ea53e3 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea53e3)
#29 0x0000000006ea6326 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea6326)
#30 0x0000000006eaec86 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eaec86)
#31 0x0000000006eaf4ca clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eaf4ca)
#32 0x0000000006dc3cd0 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc3cd0)
#33 0x0000000006dc39bd clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc39bd)
#34 0x0000000006e175f6 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e175f6)
#35 0x0000000006e19d53 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+++0x6e19d53)
#36 0x0000000006ded976 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+++0x6ded976)
#37 0x0000000006ebb3e9 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ebb3e9)
#38 0x0000000006ec8c79 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#39 0x0000000006ec908a clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ec908a)
#40 0x0000000006df47d0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df47d0)
#41 0x0000000006db0bf6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db0bf6)
#42 0x0000000006db1ae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ae5)
#43 0x0000000006db1ed0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ed0)
#44 0x0000000006d92a63 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d92a63)
#45 0x0000000004fef9d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef9d8)
#46 0x00000000053092c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53092c5)
#47 0x0000000005288e0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5288e0e)
#48 0x0000000005405b2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5405b2d)
#49 0x0000000000de5fc2 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5fc2)
#50 0x0000000000ddc8fa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#51 0x0000000000ddca7d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#52 0x0000000005058e89 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#53 0x000000000442b0d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b0d4)
#54 0x00000000050594b6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#55 0x0000000005018592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5018592)
#56 0x000000000501953e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x501953e)
#57 0x00000000050210f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50210f5)
#58 0x0000000000de2324 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde2324)
#59 0x0000000000c9954a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9954a)
#60 0x00007145f0629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#61 0x00007145f0629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#62 0x0000000000ddc395 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc395)
```
Contributor guide
Research direction
Reproduce the assertion with the FramedSpan example and inspect the template-deduction path identified in the stack trace, especially SemaTemplateDeduction.cpp. The fix is done when Clang no longer crashes while correcting ArrayDat and instead emits the expected typo-correction diagnostic; add or run a regression test if the relevant test location is identified.
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