[clang][Sema] Assertion failure in DiagnoseUnexpandedParameterPack with diagnose_if on pack
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
It is generated by a fuzzer, looks like a variant of #93269, while the assertion looks like https://github.com/llvm/llvm-project/issues/112352. It seems to be introduced after clang 18 since it doesn't crash on clang 18.1.0
source code
```cxx
template
void f() {
[] __attribute((diagnose_if(vals))) {}
}
```
https://godbolt.org/z/74dTne6h6
```
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
:1:12: error: unknown type name 'bar'
1 | template
| ^
:4:9: warning: lambda without a parameter clause is a C++23 extension [-Wc++23-extensions]
4 | __attribute((diagnose_if(vals))) {}
| ^
| ()
:4:22: error: 'diagnose_if' attribute takes at least 3 arguments
4 | __attribute((diagnose_if(vals))) {}
| ^
:4:44: error: expected ';' after expression
4 | __attribute((diagnose_if(vals))) {}
| ^
| ;
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp:559: bool clang::Sema::DiagnoseUnexpandedParameterPack(clang::Expr*, clang::Sema::UnexpandedParameterPackContext): Assertion `(!Unexpanded.empty() || LambdaReferencingOuterPacks) && "Unable to find unexpanded parameter packs"' 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 -fsyntax-only --std=c++20
1. :6:3: current parser token '}'
2. :2:13: parsing function body 'f'
3. :2:13: in compound statement ('{}')
#0 0x0000000004561238 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4561238)
#1 0x000000000455e064 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455e064)
#2 0x000000000455e684 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455e684)
#3 0x000000000449a6f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000079d863e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x000079d863e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x000079d863e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x000079d863e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x000079d863e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x000079d863e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000000007b0c404 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7b0c404)
#11 0x00000000074de3de clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74de3de)
#12 0x000000000781071e clang::Sema::ActOnExprStmt(clang::ActionResult, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x781071e)
#13 0x0000000006faf7c4 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6faf7c4)
#14 0x0000000006fa6b54 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fa6b54)
#15 0x0000000006fa7539 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fa7539)
#16 0x0000000006fafeae clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fafeae)
#17 0x0000000006fb06ca clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fb06ca)
#18 0x0000000006eb4c53 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb4c53)
#19 0x0000000006eeb943 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+++0x6eeb943)
#20 0x0000000006fbc670 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fbc670)
#21 0x0000000006fc9ed9 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#22 0x0000000006fca2ea clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6fca2ea)
#23 0x0000000006ef4550 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ef4550)
#24 0x0000000006eb04a6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb04a6)
#25 0x0000000006eb1395 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb1395)
#26 0x0000000006eb1780 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eb1780)
#27 0x0000000006e92243 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e92243)
#28 0x000000000539f2c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x539f2c5)
#29 0x000000000531de68 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x531de68)
#30 0x000000000549bb8d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x549bb8d)
#31 0x0000000000df489b cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdf489b)
#32 0x0000000000deb1fa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#33 0x0000000000deb37d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#34 0x00000000050e7ce9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x000000000449ab34 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x449ab34)
#36 0x00000000050e8316 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x00000000050a69f2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50a69f2)
#38 0x00000000050a799e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50a799e)
#39 0x00000000050af645 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50af645)
#40 0x0000000000df0c24 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdf0c24)
#41 0x0000000000ca7a3a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca7a3a)
#42 0x000079d863e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x000079d863e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000deac95 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdeac95)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the crash with the C++ source and compiler invocation in the issue, then inspect clang/lib/Sema/SemaTemplateVariadic.cpp around DiagnoseUnexpandedParameterPack at line 559. Compare the behavior with Clang 18.1.0 and the current assertion build; done means this reproducer no longer triggers the assertion while diagnostics remain handled normally.
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
- Needs clarification
- Newbie friendliness
- 45/100