llvm / llvm/llvm-project

[clang] Assertion `(!Result || *Result == Size) && "inconsistent pack sizes"' failed.

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

Description

Reproducer:
https://godbolt.org/z/hvrb6YjYY
```cpp
template struct X {};

template struct A {
template A(X, Ts (*...qs)[Ns]);
};

template
using AA = A;

AA a{};
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp:1121: clang::UnsignedOrNone clang::Sema::getNumArgumentsInExpansionFromUnexpanded(llvm::ArrayRef, clang::SourceLocation> >, const clang::MultiLevelTemplateArgumentList&): Assertion `(!Result || *Result == Size) && "inconsistent pack sizes"' 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. :10:7: current parser token ';'
#0 0x00000000044f6f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f6f18)
#1 0x00000000044f3d44 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f3d44)
#2 0x00000000044f4364 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f4364)
#3 0x0000000004431ac8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000071a9aa242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x000071a9aa2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x000071a9aa242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x000071a9aa2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x000071a9aa22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x000071a9aa239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000000007a42ad4 clang::Sema::getNumArgumentsInExpansionFromUnexpanded(llvm::ArrayRef, clang::SourceLocation>>, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a42ad4)
#11 0x0000000007a42bdb clang::Sema::getNumArgumentsInExpansion(clang::QualType, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a42bdb)
#12 0x00000000079d40a9 clang::TemplateDeclInstantiator::SubstFunctionType(clang::FunctionDecl*, llvm::SmallVectorImpl&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79d40a9)
#13 0x0000000007a372ad clang::TemplateDeclInstantiator::VisitFunctionDecl(clang::FunctionDecl*, clang::TemplateParameterList*, clang::TemplateDeclInstantiator::RewriteKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a372ad)
#14 0x0000000007a38af3 clang::TemplateDeclInstantiator::VisitCXXDeductionGuideDecl(clang::CXXDeductionGuideDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a38af3)
#15 0x0000000007a3c084 void llvm::function_ref::callback_fn(long) SemaTemplateInstantiateDecl.cpp:0:0
#16 0x00000000088c92f1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x88c92f1)
#17 0x00000000079d3ada clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79d3ada)
#18 0x00000000079d5513 clang::Sema::InstantiateFunctionDeclaration(clang::FunctionTemplateDecl*, clang::TemplateArgumentList const*, clang::SourceLocation, clang::Sema::CodeSynthesisContext::SynthesisKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79d5513)
#19 0x00000000078e455a (anonymous namespace)::BuildDeductionGuideForTypeAlias(clang::Sema&, clang::TypeAliasTemplateDecl*, clang::FunctionTemplateDecl*, clang::SourceLocation) SemaTemplateDeductionGuide.cpp:0:0
#20 0x000000000792adb8 clang::Sema::DeclareImplicitDeductionGuides(clang::TemplateDecl*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x792adb8)
#21 0x000000000750aa0f LookupDirect(clang::Sema&, clang::LookupResult&, clang::DeclContext const*) SemaLookup.cpp:0:0
#22 0x000000000750acb1 clang::Sema::LookupQualifiedName(clang::LookupResult&, clang::DeclContext*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x750acb1)
#23 0x00000000074d03ec clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d03ec)
#24 0x00000000071a142d clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a142d)
#25 0x00000000071a34cd clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a34cd)
#26 0x00000000071d4948 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71d4948)
#27 0x0000000006e1e474 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1e474)
#28 0x0000000006e2b92a 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+++0x6e2b92a)
#29 0x0000000006de8ecb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de8ecb)
#30 0x0000000006de96cf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de96cf)
#31 0x0000000006df1151 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df1151)
#32 0x0000000006df2085 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df2085)
#33 0x0000000006dd2f4a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dd2f4a)
#34 0x0000000005002698 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5002698)
#35 0x0000000005320cd5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5320cd5)
#36 0x000000000529f8f8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x529f8f8)
#37 0x000000000541d4cd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x541d4cd)
#38 0x0000000000de4f6b cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde4f6b)
#39 0x0000000000ddb8ca ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#40 0x0000000000ddba4d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#41 0x000000000506caf9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#42 0x0000000004431f04 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4431f04)
#43 0x000000000506d126 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#44 0x000000000502b5e2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x502b5e2)
#45 0x000000000502c58e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x502c58e)
#46 0x0000000005034235 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5034235)
#47 0x0000000000de12f4 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde12f4)
#48 0x0000000000c99b7a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc99b7a)
#49 0x000071a9aa229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#50 0x000071a9aa229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#51 0x0000000000ddb365 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddb365)
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

Run the supplied C++20 reproducer in an assertion-enabled Clang build, then inspect clang/lib/Sema/SemaTemplateVariadic.cpp:1121 and getNumArgumentsInExpansionFromUnexpanded. Done means this input no longer aborts with the inconsistent pack sizes assertion and the behavior is covered by a suitable regression test.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.