Skip to content

Crash for captured structured bindings which binding to array or data member #704

@flovent

Description

@flovent
struct S
{
    int x;
};

void foo()
{
    S s{1};
    auto& [x] = s;
    auto g    = [x]() {};
}
void bar()
{
    int arr[]{1, 2};
    auto& [x, _] = arr;
    auto g       = [x]() {};
}

cppinsights will crash on these two examples, which can be reproduced in website and insights built from main branch

Here is the stack trace:

 #0 0x0000558bcd1330d0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./insights+0x2e140d0)
 #1 0x0000558bcd130699 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007fb3c83ea520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000558bca61b60a clang::VarDecl::getInitStyle() const /usr/local/include/clang/AST/Decl.h:1415:57
 #4 0x0000558bca60a799 clang::insights::CodeGenerator::InsertArg(clang::CXXRecordDecl const*) /root/cppinsights/CodeGenerator.cpp:4133:27
 #5 0x0000558bca60fe36 clang::insights::CodeGenerator::HandleLambdaExpr(clang::LambdaExpr const*, clang::insights::CodeGenerator::LambdaHelper&) /root/cppinsights/CodeGenerator.cpp:4739:1
 #6 0x0000558bca603bd4 clang::insights::CodeGenerator::InsertArg(clang::LambdaExpr const*) /root/cppinsights/CodeGenerator.cpp:2869:9
 #7 0x0000558bca60cf00 clang::insights::CodeGenerator::InsertArg(clang::Stmt const*) /root/cppinsights/CodeGeneratorTypes.h:60:1
 #8 0x0000558bca5fc31a clang::insights::CodeGenerator::InsertArg(clang::VarDecl const*)::'lambda1'()::operator()() const /root/cppinsights/CodeGenerator.cpp:1451:25
 #9 0x0000558bca61331f void llvm::function_ref<void ()>::callback_fn<clang::insights::CodeGenerator::InsertArg(clang::VarDecl const*)::'lambda1'()>(long) /usr/local/include/llvm/ADT/STLFunctionalExtras.h:47:40
#10 0x0000558bca666e80 llvm::function_ref<void ()>::operator()() const /usr/local/include/llvm/ADT/STLFunctionalExtras.h:69:62
#11 0x0000558bca611a18 clang::insights::CodeGenerator::WrapInParensIfNeeded(bool, llvm::function_ref<void ()>, clang::insights::CodeGenerator::AddSpaceAtTheEnd) /root/cppinsights/CodeGenerator.cpp:5135:1
#12 0x0000558bca5fd3e3 clang::insights::CodeGenerator::InsertArg(clang::VarDecl const*) /root/cppinsights/CodeGenerator.cpp:1454:13
#13 0x0000558bca60c6f0 clang::insights::CodeGenerator::InsertArg(clang::Decl const*) /root/cppinsights/CodeGeneratorTypes.h:26:1
#14 0x0000558bca60ae08 clang::insights::CodeGenerator::InsertArg(clang::DeclStmt const*) /root/cppinsights/CodeGenerator.cpp:4196:5
#15 0x0000558bca60d500 clang::insights::CodeGenerator::InsertArg(clang::Stmt const*) /root/cppinsights/CodeGeneratorTypes.h:84:1
#16 0x0000558bca601e8f clang::insights::CodeGenerator::HandleCompoundStmt(clang::CompoundStmt const*) /root/cppinsights/CodeGenerator.cpp:2460:38
#17 0x0000558bca601d22 clang::insights::CodeGenerator::InsertArg(clang::CompoundStmt const*) /root/cppinsights/CodeGenerator.cpp:2432:5
#18 0x0000558bca60d540 clang::insights::CodeGenerator::InsertArg(clang::Stmt const*) /root/cppinsights/CodeGeneratorTypes.h:85:1
#19 0x0000558bca5fe361 clang::insights::CodeGenerator::InsertMethodBody(clang::FunctionDecl const*, unsigned long) /root/cppinsights/CodeGenerator.cpp:1673:9
#20 0x0000558bca5fe693 clang::insights::CodeGenerator::InsertArg(clang::FunctionDecl const*) /root/cppinsights/CodeGenerator.cpp:1715:31
#21 0x0000558bca60c8bf clang::insights::CodeGenerator::InsertArg(clang::Decl const*) /root/cppinsights/CodeGeneratorTypes.h:35:1
#22 0x0000558bca77b9eb CppInsightASTConsumer::HandleTranslationUnit(clang::ASTContext&) /root/cppinsights/Insights.cpp:255:37
#23 0x0000558bcace5adc clang::ParseAST(clang::Sema&, bool, bool) (./insights+0x9c6adc)
#24 0x0000558bca79fcd8 clang::FrontendAction::Execute() (./insights+0x480cd8)
#25 0x0000558bca7d85ab clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (./insights+0x4b95ab)
#26 0x0000558bcd1c1977 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (./insights+0x2ea2977)
#27 0x0000558bcd1bb005 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (./insights+0x2e9c005)
#28 0x0000558bcd1bd1c4 clang::tooling::ToolInvocation::run() (./insights+0x2e9e1c4)
#29 0x0000558bcd1bf587 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (./insights+0x2ea0587)
#30 0x0000558bca777f28 main /root/cppinsights/Insights.cpp:465:20
#31 0x00007fb3c83d1d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#32 0x00007fb3c83d1e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#33 0x0000558bca5e47f5 _start (./insights+0x2c57f5)
Segmentation fault (core dumped)

It seems like that only binding to tuple case is handled for captured structured binding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions