[clang] [Clang][SemaCXX] Fix bug where unexpanded lambda captures where assumed to have size 1 (PR #101385)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 31 19:09:54 PDT 2024
zyn0217 wrote:
I remembered @LYP951018 shared me with a case involving PackIndexingExprs that was incorrectly rejected due to the mishandling of PackExpansionExprs:
```cpp
namespace init_capture_pack {
void init_capture() {
auto L = [](auto... x) {
return [x...](auto... y) {
return [... w = y]() {
return w...[3];
};
};
};
static_assert(L()(0, 1, 2, 3)() == 3);
}
```
I have prepared for a fix on my branch https://github.com/zyn0217/llvm-project/commit/72fc2fcf472066a78c1496119aabf23a93c06ca0, which somehow relies on this "the unexpanded pack should have size 1" feature. I applied this PR locally only to find we ran into a crash with the case afterward.
```
bool clang::Sema::DiagnoseUnexpandedParameterPack(Expr *, UnexpandedParameterPackContext): Assertion `!Unexpanded.empty() && "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: ../llvm-project-Build/BuildDebug/bin/clang -fsyntax-only -fno-crash-diagnostics -std=c++20 /clangd-test/pack-indexing.cpp -DCRASH
1. /clangd-test/pack-indexing.cpp:11:19: current parser token ')'
2. /clangd-test/pack-indexing.cpp:1:1: parsing namespace 'init_capture_pack'
3. /clangd-test/pack-indexing.cpp:3:21: parsing function body 'init_capture_pack::init_capture'
4. /clangd-test/pack-indexing.cpp:3:21: in compound statement ('{}')
5. /clangd-test/pack-indexing.cpp:4:12: instantiating function definition 'init_capture_pack::init_capture()::(anonymous class)::operator()<>'
#11 0x00007f68109c9dad clang::Sema::DiagnoseUnexpandedParameterPack(clang::Expr*, clang::Sema::UnexpandedParameterPackContext) /repo/llvm-project/clang/lib/Sema/SemaTemplateVariadic.cpp:427:43
#12 0x00007f681049bdd1 clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*, bool) /repo/llvm-project/clang/lib/Sema/SemaStmt.cpp:3782:7
#13 0x00007f681091c6a3 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::RebuildReturnStmt(clang::SourceLocation, clang::Expr*) /repo/llvm-project/clang/lib/Sema/TreeTransform.h:1501:22
#14 0x00007f68109045d7 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformReturnStmt(clang::ReturnStmt*) /repo/llvm-project/clang/lib/Sema/TreeTransform.h:8288:23
#15 0x00007f68108be03e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) /repo/llvm-project-Build/BuildDebug/tools/clang/include/clang/AST/StmtNodes.inc:926:1
#16 0x00007f68108dabbb clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) /repo/llvm-project/clang/lib/Sema/TreeTransform.h:7859:38
```
https://github.com/llvm/llvm-project/pull/101385
More information about the cfe-commits
mailing list